[英]How to fetch history of user specific push notifications from parse in iOS?
[英]iOS/Parse - Sending Push Notifications to Specific User
我正在开发一个应用程序,允许“当前用户”查看其他用户发布的事件。 当前用户加入活动时,我想向发布活动的用户发送推送通知。 我已经使用Parse为我的应用设置了推送通知。 我可以通过频道向所有用户发送推送通知,但我仍然无法弄清楚如何向特定用户发送推送通知。 我能够在手机上收到推送通知。
我尝试将设备与具有以下代码的用户相关联:
PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [PFUser currentUser];
[installation saveInBackground];
不幸的是 - 这会让我的应用程序崩溃 不确定为什么没有错误消息。
我正在考虑使用以下代码将推送通知发送给特定用户。 (这是我从Parse文档获得的代码)
// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
[pushQuery whereKey:@"injuryReports" equalTo:YES];
// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setMessage:@"Willie Hayes injured by own pop fly."];
[push sendPushInBackground];
谢谢,
首先需要在用户和安装之间创建关系。 请记住,iOS上的通知会发送到设备,因为Apple通知系统对您的用户一无所知。
[[PFInstallation currentInstallation] setObject:[PFUser currentUser] forKey:@"user"];
[[PFInstallation currentInstallation] saveEventually];
现在您的代码更易于使用:
// Create our Installation query
PFQuery *pushQuery = [PFInstallation query];
// only return Installations that belong to a User that
// matches the innerQuery
[query whereKey:@"user" matchesQuery: pushQuery];
// Send push notification to query
PFPush *push = [[PFPush alloc] init];
[push setQuery:pushQuery]; // Set our Installation query
[push setMessage:@"Willie Hayes injured by own pop fly."];
[push sendPushInBackground];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.