Getting Started
Requirements
The minimal iOS version of an application using the ReachFive iOS SDKs has to be 13
.
To initialize the ReachFive client:
-
You need a Domain URL and Client ID.
-
You must whitelist all available domains where the ReachFive SDK will be used.
This is done in the Allowed Origins (CORS) field of your ReachFive console, in the Settings menu.
iOS specific prerequisites
-
The client must be a
First-party client
withToken Endpoint Authentication Method
set toNone
. -
You must have the schemes registered in
Allowed Callback URLs
. -
You should enforce PKCE for security purposes and enable Refresh Tokens for convenience.
For more on configuring a client, see Set up a client.
Installation
ReachFive SDKs are available with Swift Package Manager and Cocoapods as independent modules.
You can also find releases directly on the ReachFive repo at ReachFive iOS SDK. |
Below, you’ll find a description and instructions for installation for each module.
SDK Core
The core SDK contains all the main tools, interfaces, and methods related to standard authentication by identifier and password, passkey, passwordless, and so on.
Installation
-
Add this line to your
Podfile
file, replacingx
with the latest version:pod 'Reach5', '~> x'
-
Then run:
pod install
Add the package dependency with XCode using this package URL:
https://github.com/ReachFive/reachfive-ios.git
Or directly add this to the dependencies in Package.swift
dependencies: [
.package(url: "https://github.com/ReachFive/reachfive-ios.git", .upToNextMajor(from: "master"))
]
Configuration
Configure your application’s Info.plist
file with the following XML snippet:
<!-- Info.plist -->
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>reachfive-${clientId}</string>
</array>
</dict>
</array>
See Info.plist reference for a comprehensive look at the file. |
Facebook native provider
This module uses the Facebook native SDK to provide a better user experience.
Refer to the Meta Connect (Facebook Login) guide to create your Facebook application. |
Installation
-
Add this line to your
Podfile
file, replacingx
with the latest version:pod 'Reach5Facebook', '~> x'
-
Then run:
pod install
Add the package dependency with XCode using this package URL:
https://github.com/ReachFive/reachfive-ios-facebook.git
Or directly add this to the dependencies in Package.swift
dependencies: [
.package(url: "https://github.com/ReachFive/reachfive-ios-facebook.git", .upToNextMajor(from: "master"))
]
Configuration
If you’re using the latest version of the Facebook API, remove the user_gender scope from the ReachFive client configuration to prevent any issues.
|
-
Configure the
Info.plist
file with the following XML snippet that contains data about your application:<!-- Info.plist --> <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLSchemes</key> <array> <string>fb$(YOUR_FACEBOOK_APPLICATION_ID)</string> </array> </dict> </array> <key>FacebookAppID</key> <string>$(YOUR_FACEBOOK_APPLICATION_ID)</string> <key>FacebookClientToken</key> <string>$(YOUR_FACEBOOK_CLIENT_TOKEN)</string> <key>FacebookDisplayName</key> <string>$(YOUR_APPLICATION_NAME)</string>
-
Then to use any of the Facebook dialogs (e.g., Login, Share, App Invites, etc.) that can perform an app switch to Facebook apps, include the following lines:
<!-- Info.plist --> <key>LSApplicationQueriesSchemes</key> <array> <string>fbapi</string> <string>fb-messenger-share-api</string> </array>
See Info.plist reference for a comprehensive look at the file. |
Google native provider
This module uses the Google native SDK to provide a better user experience.
Refer to the Google Connect guide to create your Google application. |
Installation
-
Add this line to your
Podfile
file, replacingx
with the latest version:pod 'Reach5Google', '~> x'
-
Then run:
pod install
Add the package dependency with XCode using this package URL:
https://github.com/ReachFive/reachfive-ios-google.git
Or directly add this to the dependencies in Package.swift
dependencies: [
.package(url: "https://github.com/ReachFive/reachfive-ios-google.git", .upToNextMajor(from: "7.0.0"))
]
Configuration
Configure the Info.plist
file with the following XML snippet that contains data about your application:
-
Add your Google Client ID to the
Info.plist
file:<!-- Info.plist --> <key>GIDClientID</key> <string>GOOGLE_CLIENT_ID</string> (1)
1 This is your Google Client ID in standard format. For example, 1234567890-abcdefg.apps.googleusercontent.com
.See Info.plist reference for a comprehensive look at the file.
-
Add your reversed Google Client ID to the URL Scheme.
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>YOUR_REVERSED_GOOGLE_CLIENT_ID</string> (1) </array> </dict> </array>
1 The URL Scheme is the reversed Google Client ID (not ReachFive’s clientID), which is your Google Client ID with the order of the dot-delimited fields reversed. For example, com.googleusercontent.apps.abcdefg-1234567890
.See Info.plist reference for a comprehensive look at the file.
WeChat Connect
As of 2024-12-02, WeChat is not yet available for our iOS SDK version master. We will update this page accordingly when it is available.
This module uses the WeChat native SDK to be able to interact with the WeChat app.
Configuration
-
Configure the
Info.plist
file with the following XML snippet that contains data about your application:<!-- Info.plist --> <key>LSApplicationQueriesSchemes</key> <array> <string>weixin</string> <string>weixinULAPI</string> <string>weixinURLParamsAPI</string> </array>
See Info.plist reference for a comprehensive look at the file. |
Configure the iOS SDK
You must configure the iOS SDK to use it. This is where you provide the values for your domain and client ID, and define which native library you want to integrate with for Social Login.
By default, the URL scheme follows this pattern: reachfive-${clientId}://callback
.
There are multiple schemes. All must be whitelisted in Allowed Callback URLs on your ReachFive Console.
Allowed URL | Notes |
---|---|
|
This callback URL is used to open the app from another app such as an email client or the web for passwordless. Other uses:
|
|
This callback URL is used for MFA verification. Available from version |
|
This callback URL is used for account recovery code verification. Available from version |
Configuration
let reachfive = ReachFive(
// The configuration parameters required to initialize the ReachFive client
sdkConfig: SdkConfig( (1)
domain: DOMAIN,
clientId: CLIENT_ID
),
// The list of the social providers needed by the application
providersCreators: [GoogleProvider(), FacebookProvider(), WeChatProvider()] (2)
)
1 | Sets the required parameters such as domain , ReachFive clientId , and the scheme . |
2 | Lists the social providers you need for your iOS application. |
Customise scheme
You can also specify a scheme manually and customise schemes as shown here.
let ReachFive = ReachFive(
sdkConfig: SdkConfig(
domain: DOMAIN,
clientId: CLIENT_ID,
scheme: "reachfive-${clientId}://myOwnScheme", (1)
mfaUri: "reachfive-${clientId}://myOwnMfaScheme", (2)
accountRecoveryUri: "reachfive-${clientId}://myOwnRecoveryScheme" (3)
)
)
1 | Where the callback scheme ends with myOwnScheme . |
2 | Where the callback mfaUri scheme ends with myOwnMfaScheme . |
3 | Where the callback accountRecoveryUri scheme ends with myOwnRecoveryScheme . |
Customise storage
Storage is used by the iOS SDK to store the PKCE code during passwordless and MFA flows.
By default it uses the UserDefaults storage, but it can be customised to be any object that implements our Storage
protocol.
For an example of a custom implementation, see ReachFive-ios: Secure storage using the keychain.
let ReachFive = ReachFive(
sdkConfig: SdkConfig(
domain: DOMAIN,
clientId: CLIENT_ID
),
storage: UserDefaultsStorage()
)
1 | This value can be any object that implements our Storage protocol. |
Initialize iOS SDK
You must initialize the iOS SDK to use it. Initializing the iOS SDK ensures the client configuration is properly fetched (which contains default scope) and native social providers are properly initialized.
You initialize your iOS client with:
reachfive.application(application, didFinishLaunchingWithOptions: launchOptions)
Full examples
The full file examples below show you were to initialize the client as well as providing context for the overall configuration and initialization.
import UIKit (1)
import Reach5
class AppDelegate: UIResponder, UIApplicationDelegate {
let DOMAIN = "Here paste your ReachFive domain" (2)
let CLIENT_ID = "Here paste your ReachFive client ID" (3)
let reachfive = ReachFive(
// The configuration parameters required to initialize the ReachFive client
sdkConfig: SdkConfig(domain: DOMAIN, clientId: CLIENT_ID)
)
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Initialize the ReachFive client
return reachfive.application(application, didFinishLaunchingWithOptions: launchOptions) (4)
}
}
1 | Import the UIKit if using it. If using another UI framework, you may not initialize provider configuration. |
2 | Your ReachFive domain such as integ-sandbox.reach5.dev . |
3 | The ReachFive client such as zhU43…51nvOM ; |
4 | Initializing the ReachFive client. |
import UIKit
import Reach5
import Reach5Facebook
import Reach5Google
import Reach5WeChat
class AppDelegate: UIResponder, UIApplicationDelegate {
let DOMAIN = "Here paste your ReachFive domain" // e.g. integ-sandbox-squad2.reach5.dev
let CLIENT_ID = "Here paste your ReachFive client ID" // e.g. zhU43aRKZtzps551nvOM
let reachfive = ReachFive(
// The configuration parameters required to initialize the ReachFive client
sdkConfig: SdkConfig(domain: DOMAIN, clientId: CLIENT_ID),
// The list of the social providers needed by the application
providersCreators: [GoogleProvider(), FacebookProvider(), WeChatProvider()]
)
// Return the ReachFive client
static func reachfive() → ReachFive { (1)
let app = UIApplication.shared.delegate as! AppDelegate
return app.reachfive
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) → Bool {
reachfive.addPasswordlessCallback { result in
// Check result and extract the authToken if the callback was successful, then continue your flow (for example redirect to the profile page)
}
// Initialize the ReachFive client
return reachfive.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) → Void) → Bool {
reachfive.application(application, continue: userActivity, restorationHandler: restorationHandler) (2)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) → Bool {
reachfive.application(app, open: url, options: options) (3)
}
func applicationDidBecomeActive(_ application: UIApplication) {
reachfive.applicationDidBecomeActive(application) (4)
}
}
1 | An example of how to access the ReachFive object from within the app. |
2 | This method is used to handle universal links which are used by providers. |
3 | This method is used to handle callback schemes which are used by passwordless, MFA and account recovery, as well as providers. |
4 | This method is used to provide functionality to the providers. |
iOS methods
The sidebar contains are all the functions/methods accessible via the iOS SDK.
In all the code examples, the ReachFive client is instantiated and stored in your AppDelegate
class.
You can access it through the AppDelegate.reachfive()
method as shown here and in Configuration.
// Return the ReachFive client
static func reachfive() -> ReachFive {
let app = UIApplication.shared.delegate as! AppDelegate
return app.reachfive
}
Info.plist reference
If you configure all four SDKs, your Info.plist
file should contain the following XML
Snippet.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb1634029666893228</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.abcdefg-1234567890</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>reachfive-TYAIHFRJ2a1FGJ1T8pKD</string>
</array>
</dict>
</array>
<key>GIDClientID</key>
<string>1234567890-abcdefg.apps.googleusercontent.com</string>
<key>FacebookAppID</key>
<string>1634029666893228</string>
<key>FacebookClientToken</key>
<string>ec97b21afcd93ce699091a774a90e2e5</string>
<key>FacebookDisplayName</key>
<string>Reach5 SDK Mobile</string>
<key>GIDClientID</key>
<string>abcdefg-1234567890.apps.googleusercontent.com</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
<string>weixinULAPI</string>
<string>weixinURLParamsAPI</string>
<string>fbapi</string>
<string>fb-messenger-share-api</string>
</array>