Link SDK for iOS
In this guide we will walk you through the steps to integrate the Link SDK for iOS into your app.
Copy linkSet up your Xcode project
Open up Xcode and create a new iOS project for iOS 16+.
Copy linkImport the LinkKit framework
There are two alternative approaches to importing the LinkKit framework:
Copy linkA. Using Swift Package Manager
In Project navigator on the left, select your project and then select the corresponding entry under "PROJECT" in the area to the right.
Open "Package Dependencies" tab and click +
at the bottom left of the "Packages" section:
In the modal, paste https://github.com/enode/enode-link-ios
in the search field at the top right and then select enode-link-ios
entry in the table of the middle of the screen.
Click Add Package
at the bottom right:
Click Add Package
again at the bottom right of the new modal:
enode-link-ios
should now be among items in the "Packages" section:
Copy linkB. Using a local SDK bundle
First, download the LinkKit framework.
Extract the zip archive and keep the folder LinkKit.xcframework
somewhere convenient.
Under your build target, open the General tab, import the framework by dragging the LinkKit.xcframework
folder into the Framework, Libraries and Embedded Content section:
Copy linkConfiguring Bluetooth access
Start by heading to the Info tab and add a Custom iOS Target Property by clicking on the +
icon in the list of key value pairs. Use the following values.
Key | Value |
---|---|
Key | NSBluetoothAlwaysUsageDescription |
Type | String |
Value | “Our app requires Bluetooth to connect with energy devices, enabling efficient device management and enhanced user experience.” |
Use the iOS target properties to inform the user about the required bluetooth access.
Copy linkIntegrating the SDK
In your application section where you want to open LinkKit, import the SDK:
import LinkKit
Ensure you have linkToken
from the previous step and pass it into the handler:
private var handler: Handler?
self.handler = Handler(linkToken: linkToken) { linkResult in
switch linkResult {
case .success:
// Handle success
case .failure(let error):
// Handle error
}
}
self.handler?.present(from: self) // self is a UIViewController
Here’s how an alternative approach for SwiftUI (using linkKitSheet
) can be used, but the code above would also work.
import SwiftUI
import LinkKit
struct ContentView: View {
// ...
@State private var isPresented = false
var body: some View {
Button(action: {
self.isPresented = true
}) {
Text("Open LinkKit")
}
.linkKitSheet(isPresented: $isPresented, linkToken: linkToken) { linkResult in
switch linkResult {
case .success:
// Handle success
case .failure(let error):
// Handle error
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Once run, Link UI will open in your application and guide your user through the process of linking. When successful, the "Complete" button will dismiss the modal and return users to the previous screen.
If a user did not complete Link UI or dismisses the window, you will receive a LinkResult
with a failure
and one of the errors below.
Copy linkTheming the SDK
You can customize the color which is used for all interactive elements in the top bar (cancel and refresh buttons) and bottom bar (the back and forwards buttons) that wraps Link UI. To do so, you can set the tintColor property of the containing window that presents the Link SDK.
Below is an example of how to set the tintColor
to green in the AppDelegate.swift
or SceneDelegate.swift
file.
...
self.window?.tintColor = .systemGreen
Copy linkAPI Reference
Copy linkLinkResult
& LinkError
For details on errors the SDK provides, see details below.
public enum LinkResult {
case success
case failure(LinkError)
}
public typealias HumanReadableMessage = String
public enum LinkError : Error {
// Unknown error occurred
case unknown
// Required linkToken parameter was not found
case missingLinkToken
// Supplied linkToken was malformed
case malformedLinkToken(LinkKit.MalformedLinkTokenError)
// Link UI was dismissed by you (e.g., by calling `dismiss()`)
case dismissedViaDismissFunction
// Link UI was dismissed by the user (e.g., tapping "Close")
case cancelledByUser
// Enode was unable to complete linking due to a service error
case backendError(LinkKit.HumanReadableMessage)
// Link UI itself initiated the closing of the modal
case earlyExitRequestedFromFrontend(LinkKit.HumanReadableMessage?)
}
public enum MalformedLinkTokenError : Error {
case couldNotCreateDataFromTheToken
case couldNotParseJsonFromTheToken
case jsonDeserializationError(LinkKit.HumanReadableMessage)
case couldNotParseLinkUrlAndRedirectUriFromTheToken
case couldNotCreateURLFromLinkUrl
case couldNotFindHostFromLinkURL
case hostOfLinkURLIsNotEnodecomOrEnodeio
}
Copy linkOther ways to integrate
Integrating with the Link SDK for Android
Integrating with the Link SDKs in React Native