解析推送通知:如何使用自定义负载 [英] Parse push notification: How to use custom payload

查看:54
本文介绍了解析推送通知:如何使用自定义负载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 json 在 Parse 中发送推送通知.

I'm using the following json to send a push notification in Parse.

{
  "alert": "Push title goes here",
  "sound": "",
  "url": "emap://video/4000"
}

网址 emap://video/4000 指向应用程序内的特定视频,如果我在 Safari 中输入该视频并按回车键.我希望用户在点击通知时被发送到这个视频.为什么上面的JSON没有实现这个?

The url emap://video/4000 points to a specific video inside the app if I type that in Safari and hit enter. I want the user to be sent to this video when he clicks on the notification. Why doesn't the above JSON achieve this?

推荐答案

所以说我们正在发送这个负载:

So say we are sending this payload :

NSDictionary *data = @{
    @"alert" : @"some generic message here",
    @"badge" : @"Increment",
    @"sound" : @"default",
    @"url" : @"emap://video/4000"
};    

当用户与之交互时,会采取相应的行动:

And when the user interacts with it act accordingly :

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    if (application.applicationState == UIApplicationStateInactive) {
      [self handleRemoteNotificationWithPayload:userInfo];
    }
}

-(void)handleRemoteNotificationWithPayload:(NSDictionary *)payload {

    if (payload) {
       NSString *urlLink = [payload valueForKey:@"url"];
       // perform segue or tab bar selectedIndex or open webView whatever you want after checking if user is launching from notification :
    }
}

您还应该在 application didFinishLaunchingWithOptions: 中调用它,以防用户应用程序已终止或从内存中释放:

You should also call this in application didFinishLaunchingWithOptions: in case the users app has been terminated or released from memory:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
    NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
    [self handleRemoteNotificationWithPayload:notificationPayload];
...
}

这篇关于解析推送通知:如何使用自定义负载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆