我已使用push
实施了parse
通知。我正在使用此代码发送通知:
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"deviceType" equalTo:@"ios"];
// Send push notification to query
[PFPush sendPushMessageToQueryInBackground:pushQuery
withMessage:@"Hello World!"];
在AppDelegate.m
我有
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
因为它是解析PUSH的默认方法。但我希望根据收到的不同信息来做不同的事情。
如何从UserInfo
字典中提取消息。?
答案 0 :(得分:0)
PFQuery *pushQuery = [PFInstallation query];
//Send push to a particular user, granted you saved that with their installation
//Or customize your query anyway you want
[pushQuery whereKey:@"user" equalTo:_user];
NSMutableDictionary *pushDictionary = [[NSMutableDictionary alloc] init];
pushDictionary[@"type"]=@"message";
pushDictionary[@"alert"]=@"YOUR MESSAGE";
//You can use anything here... pushDictionary[@"a"]=@"b" etc...
[PFPush sendPushDataToQueryInBackground:pushQuery withData:pushDictionary];
以上代码发送您的推送
现在在AppDelegate.m
中- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
NSLog(@"userInfo: %@",userInfo);
if ([[userInfo objectForKey:@"type"] isEqualToString:@"message"]) {
//You received a push of type "message", do whatever...
}
else{
//Push is something else...
}
}