使用Parse,我的推送通知工作正常。 我的应用程序是一个RSS新闻源,我不时发送推送通知,我的问题是我不知道如何在用户收到推送通知时处理推送通知。 我已将所有RSS源列在plist文件中,例如我的plist文件如何显示:
rss_sources
↓
01
↓
url http://www.newyorkNews.com/rss.xml
title: new york News
↓
02
↓
url http://www.harlemNews.com/rss.xml
title: harlem news
我想要做的是,检查标题是否等于推送通知的开头(因为我是发送推送的人,我会写下确切的标题),如果它,那么它将转到我在代码中设置的一些index.row。 我甚至可能在这里提供什么? 如果这是另一种方式,我会很高兴听到解决方案,或一些类似于我的情况的代码模式,所以我可以从中获得启发。
答案 0 :(得分:2)
您所要做的就是为您的有效负载设置一个通用密钥,在您的情况下看起来像标题。因此,当您发送推送(作为数据/有效负载/ 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
解析SDK https://parse.com/docs/ios/api/
从Parse控制台推送通知:
{
"aps" : {
"alert" : "New NY Time Article",
"badge" : 1,
"sound" : "default",
"title" : "NY Times"
}
}