Deeplinks & URLs

It's important to bring user to the right section of your app when he opens a notification.

That could be done on 3 ways:

  • Using standard deeplinks
  • Using 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.

Screen_Shot_2017-09-26_at_14.57.42.png

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;
        }
    }

 

URL scheme

If you are using a custom URL scheme in your app. You can can use the "Open URL" action on the platform.

Screen_Shot_2017-09-26_at_15.46.32.png

For iOS more information on implementing a custom URL scheme can be found here

For android more information on implementing a custom URL scheme can be found here.

 

Custom payloads

Custom payloads can also be used to navigate a user to specific pages of your app.

Screen_Shot_2017-09-26_at_15.53.14.png

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"));
            }
        }
    }

 

 

Have more questions? Submit a request

0 Comments

Article is closed for comments.