如何处理解析推送响应

时间:2015-06-09 09:32:27

标签: ios objective-c parse-platform push-notification

我已使用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字典中提取消息。?

1 个答案:

答案 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...
    }

}