Skip to content
This repository was archived by the owner on Jul 22, 2020. It is now read-only.

Commit 3bfbaea

Browse files
authored
Update Deep Linking section in README (#61)
1 parent 32af84d commit 3bfbaea

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

README.md

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,47 @@ Custom events can be tracked using the `track` function and user fields can be m
207207
#### Handling links from push notifications
208208
Push notifications and action buttons may have `openUrl` actions attached to them. When a URL is specified, the SDK first calls `urlDelegate` specified in your `IterableConfig` object. You can use this delegate to handle `openUrl` actions the same way as you handle normal deep links. If the delegate is not set or returns NO, the SDK will open Safari with that URL.
209209

210+
```objective-c
211+
// AppDelegate.m
212+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
213+
...
214+
// Initialize Iterable SDK
215+
IterableConfig *config = [[IterableConfig alloc] init];
216+
...
217+
config.urlDelegate = self;
218+
[IterableAPI initializeWithApiKey:@"YOUR API KEY" launchOptions:launchOptions config:config];
219+
...
220+
}
221+
222+
- (BOOL)handleIterableURL:(NSURL *)url context:(IterableActionContext *)context {
223+
// Assuming you have a DeeplinkHandler class that handles all deep link URLs and navigates to the right place in the app
224+
return [[DeeplinkHandler sharedInstance] handleUrl:url];
225+
}
226+
```
227+
210228
#### Handling email links
211229
For Universal Links to work with link rewriting in emails, you need to set up apple-app-site-association file in the Iterable project. More instructions here: [Setting up iOS Universal Links](https://support.iterable.com/hc/en-us/articles/115000440206-Setting-up-iOS-Universal-Links)
212230

213-
From your `UIApplicationDelegate`'s [application:continueUserActivity:restorationHandler:](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application?language=objc) call `resolveApplinkURL` along with a callback to handle the original deeplink url. You can use this method for any incoming URLs, as it will execute the callback without changing the URL for non-Iterable URLs.
231+
If you already have a `urlDelegate` (see *Handling links from push notifications* section above), the same handler can be used for email deep links by calling `handleUniversalLink:` in your `UIApplicationDelegate`'s [application:continueUserActivity:restorationHandler:](https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623072-application?language=objc):
232+
233+
```objective-c
234+
- (BOOL)application:(UIApplication *)application
235+
continueUserActivity(NSUserActivity *)userActivity
236+
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
237+
// This will track the click, retrieve the original URL and call `handleIterableURL:context:` with the original URL
238+
return [IterableAPI handleUniversalLink:userActivity.webpageURL];
239+
}
240+
```
241+
242+
Alternatively, call `getAndTrackDeeplink` along with a callback to handle the original deeplink url. You can use this method for any incoming URLs, as it will execute the callback without changing the URL for non-Iterable URLs.
214243
215244
Swift:
216245
217246
```swift
218247
func application(_ application: UIApplication, continue userActivity: NSUserActivity,
219248
restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
220249
221-
IterableAPI.resolveApplinkURL(userActivity.webpageURL!, callback: {
250+
IterableAPI.getAndTrackDeeplink(userActivity.webpageURL!, callbackBlock: {
222251
(originalURL) in
223252
//Handle Original URL deeplink here
224253
});
@@ -233,8 +262,8 @@ Objective-C:
233262
continueUserActivity(NSUserActivity *)userActivity
234263
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler {
235264

236-
[IterableAPI resolveApplinkURL:userActivity.webpageURL callback:^(NSURL* originalURL) {
237-
//Handle Original URL deeplink here
265+
[IterableAPI getAndTrackDeeplink:iterableLink callbackBlock:^(NSString* originalURL) {
266+
//Handle Original URL deeplink here
238267
}];
239268

240269
return true;

0 commit comments

Comments
 (0)