簡體   English   中英

使用NodeJS后端推送通知

[英]Push Notifications with NodeJS backend

我目前正在尋找針對iOS應用的推送通知。 我在后端使用PostgresSQL和NodeJS,並且在網上看時,似乎沒有直接的方法在兩個設備之間實現PEER TO PEER推送通知。 有經驗的人的任何幫助將非常有幫助。

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

如果您要沿着這條路走,我會在他們現有的服務上啟動一個新應用,然后再遷移到其他地方。 希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM