Deeplinks are a type of link that sends users directly to a specific section of an app when they open a notification.

This can be achieved in 3 ways, using:

  • Standard deeplinks
  • A URL scheme
  • Custom message payloads

Standard deeplinks

Xtremepush has a callback for deeplink strings sent from the platform that include the Go to Deeplink action.

iOS

Here is how you register the handler in the didFinishLaunchingWithOptions method in the AppDelegate:

XPush.registerDeeplinkHandler({(_ x: String) -> Void in
            
        })
[XPush registerDeeplinkHandler:^(NSString *x) {
        NSLog(@"[AppDelegate] - DeeplinkHandler: %@", x);
    }];

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")
        }
    })
[XPush registerDeeplinkHandler:^(NSString *x) {
        if ([x isEqualToString:@"checkout"])
        {
            [self goToCheckout];
        }
        else if([x isEqualToString:@"offers"])
        { 
            [self goToOffers];
        }
    }];

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.

@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"));
            }
        }
    }
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);
            }
        }
    })
[XPush registerMessageResponseHandlerWithCompletion:^(XPMessageResponse * _Nonnull 
    switch (response.action.type) {
        case XPActionType_Click:
            if (response.message.data[@"article"]){
                [self openArticle: response.message.data[@"articleId"]];
            }
            break;
    }

     completionHandler();
}];

📘

Custom handling of messages

Information on implementing the MessageResponseHandlers can be found here.