我正在使用以下json在Parse中发送推送通知。
{
"alert": "Push title goes here",
"sound": "",
"url": "emap://video/4000"
}
如果我在Safari中输入并点击输入,则网址emap://video/4000
指向应用内的特定视频。我希望用户在点击通知时发送到此视频。为什么上面的JSON没有达到这个目的?
答案 0 :(得分:1)
所以说我们发送这个有效载荷:
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:
中调用此内容:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
[self handleRemoteNotificationWithPayload:notificationPayload];
...
}