iOS - Continuity Lifecycle Module
To implement a ContinuityLifecycleModule
, a proper configuration in your DevApp is
required. Please ensure your settings are correctly configured.
The ContinuityLifecycleModule
interface is used when creating a module that handles
deeplinks originated via custom URL or universal link. This module provides an entry point
to one or more events related to handling Custom URL deeplinks originated from
Q2MobileCore via openURL or Universal Links via continue user activity.
Implementation
Implementing a ContinuityLifecycleModule
is straightforward—create an NSObject class
conforming to the ContinuityLifecycleModule protocol requirements.
import Q2ModuleInterfaces
class CustomContinuityLifecycleModule: ContinuityLifecycleModule {
private enum Constants {
static let scheme = "your-scheme"
static let path = "your-path"
}
var moduleDelegate: ModuleDelegate?
var moduleDataSource: ModuleDataSource?
public func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
// no-op
}
public func application(_ application: UIApplication, shouldOpenURL url: URL, withOptions options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool? {
handleOpenURL(url)
}
public func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool? {
willContinueUserActivityWithType(userActivityType)
}
public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool? {
handleUserActivity(userActivity)
}
public func application(_ application: UIApplication, didFailToContinueUserActivityWithType userActivityType: String, error: Error) {
// no-op
}
}
// MARK: - Handle
private extension CustomContinuityLifecycleModule {
func handleOpenURL(_ url: URL) -> Bool {
guard url.absoluteString.lowercased().contains(Constants.scheme) else {
print("CustomContinuityLifecycleModule: WON'T Handled URL Scheme | Scheme: \(Constants.scheme) | URL: \(url.absoluteString)")
return false
}
print("CustomContinuityLifecycleModule: WILL Handle URL Scheme | Scheme: \(Constants.scheme) | URL: \(url.absoluteString)")
return true
}
func willContinueUserActivityWithType(_ userActivityType: String) -> Bool {
false // return true to handle user activity
}
func handleUserActivity(_ userActivity: NSUserActivity) -> Bool {
guard let webpageURL = userActivity.webpageURL else {
return false
}
guard webpageURL.absoluteString.lowercased().contains(Constants.path) else {
print("CustomContinuityLifecycleModule: WON'T Handled Universal Link | Path: \(Constants.path) | URL: \(webpageURL.absoluteString)")
return false
}
print("CustomContinuityLifecycleModule: WILL Handled Universal Link | Path: \(Constants.path) | URL: \(webpageURL.absoluteString)")
return true
}
}
Testing Deeplink - Scheme
To test scheme deeplink within DevApp, perform the following steps:
Step 1: Add your-scheme in DevApp info.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLName</key>
<string>com.q2.mobile</string>
<key>CFBundleURLSchemes</key>
<array>
<string>your-scheme</string>
</array>
</dict>
</array>
</dict>
</plist>
Step 2: Testing the Implementation
- Run DevApp on simulator.
- Go to Safari on simulator and enter
your-scheme://
Note: You will see log message that your module has handled custom url scheme.
Testing Deeplink - Applink
Step 1: Configure Associated Domains
Example: When Q2DevApp bundle id is com.q2.mobile, then to associate module with url:
https://demo.company.com/sdx/uux.aspx?mobtest
, add the following applink in
DevApp.entitlement:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:demo.company.com</string>
</array>
</dict>
</plist>
Step 2: Testing the Implementation
- Run DevApp on simulator.
- Go to Safari on simulator and enter
https://demo.company.com/sdx/uux.aspx?mobtest
Note: You will see log message that your module has handled the universal link.