iOS
Follow these instructions to set up your iOS integration.
Setup
Argyle iOS SDK provides a way to integrate Argyle Link into your iOS app.
Requirements:
- iOS 12.0+
- Xcode 12.0+
- Swift 5+
Argyle recommends that you lock your app to portrait orientation.
Adding the SDK dependency
You can add the SDK dependency with Swift Package Manager or CocoaPods.
Swift Package Manager
Swift Package Manager, or SwiftPM, is a tool for managing the distribution of Swift code. It is integrated with the Swift build system to automate the process of downloading, compiling, and linking dependencies.
To integrate Argyle Link into your Xcode project using SwiftPM follow the Apple documentation.
Search for the argyle-link-ios package and use the version-based package requirements.
CocoaPods
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate Argyle into your Xcode project using CocoaPods, specify it in your Podfile
:
pod 'Argyle', '4.x.x'
Use pod install
and pod update
commands to install/update pods afterward.
Configuring and starting the flow
Replace YOUR_LINK_KEY
with your own linkKey
. Find your Link key in the API keys section of the Argyle Console.
class ViewController: UIViewController {
override func viewDidLoad() {
_ = Argyle.shared
.loginWith(linkKey: "YOUR_LINK_KEY", apiHost: "https://api-sandbox.argyle.com/v1")
.linkItems(["amazon_flex", "uber"]) // Can be skipped if all Link items are needed
.resultListener(self)
}
@IBAction func argyleNewUser(_ sender: Any) {
let argyle = Argyle.shared.controller
argyle.modalPresentationStyle = .fullScreen
self.present(argyle, animated: true, completion: nil)
}
}
extension ViewController: ArgyleResultListener {
func onUserCreated(token: String, userId: String) {
print("APP: onUserCreated((token: \(token), userId: \(userId))")
}
func onAccountCreated(accountId: String, userId: String, linkItemId: String) {
print("APP: onAccountCreated(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onAccountConnected(accountId: String, userId: String, linkItemId: String) {
print("APP: onAccountConnected(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onAccountUpdated(accountId: String, userId: String, linkItemId: String) {
print("APP: onAccountUpdated(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onAccountRemoved(accountId: String, userId: String, linkItemId: String) {
print("APP: onAccountRemoved(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onAccountError(accountId: String, userId: String, linkItemId: String) {
print("APP: onAccountError(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onPayDistributionSuccess(accountId: String, userId: String, linkItemId: String) {
print("APP: onPayDistributionSuccess(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onPayDistributionError(accountId: String, userId: String, linkItemId: String) {
print("APP: onPayDistributionError(accountId: \(accountId), userId: \(userId), linkItemId: \(linkItemId))")
}
func onUserCreated(token: String, userId: String) {
print("APP: onWorkerCreated((token: \(token), userId: \(userId))")
}
func onError(error: ArgyleErrorType) {
print("APP: onError(error: \(error.rawValue))")
}
func onUIEvent(name: String, properties: [String: Any]) {
print("APP: onUIEvent(name: \(name), properties: \(properties)")
}
func onTokenExpired(handler: @escaping (String) -> ()) {
handler("new_token")
}
func onClose() {
print("APP: onClose")
}
}
The
apiHost
in this iOS SDK configuration example is set to the Argyle Sandbox API (<https://api-sandbox.argyle.com/v1
>). It's a good idea to test your implementation in Sandbox mode first, then change this to the Production API (<https://api.argyle.com/v1
>) when you are ready to go live.
Closing Link programmatically
Normally, the user closes Link but you can also close it by calling Argyle.shared.close()
.
We strongly recommend upgrading the SDK as soon as there is a new version available. This helps you provide the best Argyle Link experience in your application.
To receive notifications when a new release is issued, you can watch for releases on our repositories or subscribe to our Changelog.
Configuration
Argyle Link provides multiple configuration options and callbacks that customize how this UI element functions in your application. The only argument that is mandatory when invoking Argyle Link is the linkKey
, which you can find in the Argyle Console.
By default, anytime Argyle Link is initialized, it will be treated as a new session for a new user. To ensure your users retain their previous state in Argyle Link when it is re-initialized for them, your application must use the userToken
parameter.
For a full list of Link configuration parameters, see the Link reference.
User tokens
User tokens are temporary access keys that let you start Argyle Link for an existing user.
Tokens are short-lived. Generate a new token using the API every time you initialize Argyle Link for a returning user.
You can create user tokens using the /user-tokens
endpoint.
Make sure that you request user tokens on your server-side and your client_id
and client_secret
are never exposed on the front-end.
Callbacks
For a full list of callbacks, see the Link reference.
Upgrade
See the Link SDK for iOS upgrade guide for instructions on upgrading your integration.
Updated 2 months ago