parsing推送通知:如何使用自定义有效内容

我使用下面的json在Parse中发送推送通知。

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

url emap://video/4000指向应用程序内部的一个特定的video,如果我在Safari中input,然后按Enter键。 我希望用户在点击通知时发送到此video。 为什么上面的JSON不能实现呢?

所以说我们正在发送这个有效载荷:

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

而当用户与之交互时,则相应地采取行动:

 - (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:调用此方法application didFinishLaunchingWithOptions:万一用户应用程序已被终止或从内存释放:

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