您可以使用Parse SDK 细分您希望向其发送个人消息的用户。他们的服务将于 1 月停用,但您仍然可以托管自己的 MongoDB 实例并保留其平台的全部功能。
注册您的登录用户以接收推送通知:
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:types categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
在您的 AppDelegate 中实现 didRegisterForRemoteNotificationsWithDeviceToken 方法
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)newDeviceToken {
NSLog(@"didRegisterForRemoteNotifications");
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:newDeviceToken];
if ([PFUser currentUser]) {
[currentInstallation setObject:[PFUser currentUser] forKey:@"user"];
}
[currentInstallation saveInBackground];
}
这会创建一个指向用户帐户的指针,我们将使用它来划分用户:
NSString *toUserObjectId = someUser.objectId; //someUser is a 'PFUser' object
// segment the user
PFQuery *innerQuery = [PFUser query];
[innerQuery whereKey:@"objectId" equalTo:toUserObjectId];
PFQuery *query = [PFInstallation query];
[query whereKey:@"user" matchesQuery:innerQuery];
NSDictionary *pushData = @{
@"alert": @"some message",
// @"p": someStringPayload,
@"badge": @"Increment",
@"sound": @"cheering.caf",
};
PFPush *push = [[PFPush alloc] init];
[push setData:pushData];
//[push expireAfterTimeInterval:interval];
[push setQuery:query];
[push sendPushInBackground];
如果您要走这条路,我会在他们现有的服务上启动一个新应用程序,然后迁移到其他地方。希望这会有所帮助。