使用NodeJS后端推送通知

时间:2016-08-20 05:22:13

标签: ios node.js swift push-notification apple-push-notifications

我目前正在寻找iOS应用的推送通知。我使用PostgresSQL和NodeJS作为后端,当我在网上看时,似乎没有直接的方法在两个设备之间实现PEER TO PEER推送通知。有经验的人的任何帮助都会非常有帮助。

1 个答案:

答案 0 :(得分:0)

您可以使用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];

如果你要走这条路,我会在现有服务上启动一个新应用,然后迁移到其他地方。希望这会有所帮助。