您所要做的就是为您的有效负载设置一个通用键,在您的情况下它看起来像标题。因此,当您发送推送(作为数据/有效负载/json)时,当用户收到一个推送时,您交叉引用 valueForKey:
与往常一样,我强烈建议您亲自尝试,因为这就是您学习的方式。而且我总是将 Parse 用户引导到他们的文档,因为它们的文档非常好。如果那是一件事,几乎记录得太多了。但是,如果您卡在这里是一个工作示例:
使用有效负载构造推送:
NSDictionary *data = @{
@"alert" : @"some generic message here",
@"badge" : @"Increment",
@"sounds" : @"default",
@"title" : @"NY Times" //this is whatever you want
};
//schedule the push with some options. This isn't a mandatory set up, just an example. You can do a lot with PFPushes
PFPush *push = [[PFPush alloc] init];
[push setChannels:@[ @"subscribed" ]];
[push setData:data];
[push sendPushInBackground];
现在您所要做的就是查看有效负载中键标题的值是否符合您的需求:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
. . .
// Extract the notification data from payload
NSDictionary *notificationPayload = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
NSString *newsType = [notificationPayload valueForKey:@"title"];
// perform segue or tab bar selectedIndex or whatever you want after checking if user is launching from notification :
if (notificationPayload) {
//check it title has your string
if ([newsType isEqualToString:@"NY Times"]) {
//do whatever here
} else {
}
}
}
参考资料 - 请随意使用这些参考资料,他们为我们提供了最新的资源,他们做得很好
解析 iOS 推送:https://parse.com/docs/push_guide#top/iOS
解析SDKhttps://parse.com/docs/ios/api/
从 Parse 控制台推送通知:
{
"aps" : {
"alert" : "New NY Time Article",
"badge" : 1,
"sound" : "default",
"title" : "NY Times"
}
}
作为参考,这将帮助您入门:https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW15