It's important to bring a user to the right section of your app when they open a notification.
This can be achieved in 3 ways:
- Using standard deeplinks
- Using a URL scheme
- Using custom message payloads
Standard deeplinks
Xtremepush has a callback for deeplink strings sent from the platform that include the "Go to Deeplink" action.
Objective-C:
Here is how you register the handler.
[XPush registerDeeplinkHandler:^(NSString *x) { NSLog(@"[AppDelegate] - DeeplinkHandler: %@", x); }];
Below is a simple example of how this can be used
[XPush registerDeeplinkHandler:^(NSString *x) { if ([x isEqualToString:@"checkout"]) { [self goToCheckout]; } else if([x isEqualToString:@"offers"]) { [self goToOffers]; } }];
Swift 3:
Here is how you register the handler.
XPush.registerDeeplinkHandler({(_ x: String) -> Void in })
Below is a simple example of how this can be used
XPush.registerDeeplinkHandler({(_ x: String) -> Void in switch x{ case "checkout": self.goToCheckout() case "offers": self.goToOffers() default: print("unrecognised deeplink") } })
Android:
First, you must implement the DeeplinkListener interface in your Application.java class.
public class YOUR_APPLICATION_CLASS extends Application implements DeeplinkListener {
Then you must implement the callback.
@Override public void deeplinkReceived(String link, WeakReference uiReference) { }
Below is a simple example of how this can be used
@Override public void deeplinkReceived(String link, WeakReference uiReference) { switch (link){ case "checkout": goToCheckout(); break; case "offers": goToOffers(); break; } }
Don't forget to add the DeeplinkListener object you created to PushConnector.builder:
new PushConnector.Builder(XPUSH_APP_KEY, GOOGLE_PROJECT_NUMBER)
...
.setDeeplinkListener(this)
.create(this);
URL scheme
If you are using HTTPS links or a custom URL scheme in your app you can use the "Open URL" action on the platform.
For iOS, more information on implementing a URL-based deeplinks can be found here.
For Android, more information on implementing URL-based deeplinks can be found here.
Custom payloads
Custom payloads can also be used to navigate a user to specific pages of your app.
Note: Information on implementing the MessageResponseHandlers can be found here.
Objective-C
[XPush registerMessageResponseHandlerWithCompletion:^(XPMessageResponse * _Nonnull switch (response.action.type) { case XPActionType_Click: if (response.message.data[@"article"]){ [self openArticle: response.message.data[@"articleId"]]; } break; } completionHandler(); }];
Swift 3:
XPush.registerMessageResponseHandler({(_ response: XPMessageResponse) -> Void in if response.action.type == XPActionType_Click { if (x.message.data?["article"] != nil) { self.openArticle(x.message.data!["article"] as! String); } } })
Android:
@Override public void messageResponseReceived(final Message messagePayload, HashMap<String, String> responsePayload, final WeakReference uiReference) { if (responsePayload.get("type").equals("click")) { if (messagePayload.data.containsKey("article")) { openArticle(messagePayload.data.get("article")); } } }
Comments
0 comments
Article is closed for comments.