向 Parse 发送推送通知,如何在设备中接收它

Sent push notification to Parse, how to receive it in device

我正在尝试发送和接收推送通知,因此,例如,当某个开关关闭时,另一个 phone 使用相同的应用程序会通过发送警报消息通知发生了这种情况。

推送通知已成功发送到 Parse,因为我的帐户显示所有推送通知都是由我的应用程序发送的。但是,实际上没有消息到达预期的设备。我的应用程序发送的通知列表显示每个 0 "Pushes sent"。

我已经将推送通知从 Parse 本身发送到我的设备,并且我确实收到了这些通知,所以我认为这不是通知配置的问题。

我按照 Parse 指南配置了这些,但无论如何我都会 post 我的代码: AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {


[Parse setApplicationId:@"****My app id****"
              clientKey:@"****My key****"];

UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                UIUserNotificationTypeBadge |
                                                UIUserNotificationTypeSound);
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                         categories:nil];
[application registerUserNotificationSettings:settings];
[application registerForRemoteNotifications];


return YES;
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
// Store the deviceToken in the current installation and save it to Parse. 
[PFPush storeDeviceToken:deviceToken];
[PFPush subscribeToChannelInBackground:@""];

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setObject:[PFUser currentUser] forKey:@"owner"];
[currentInstallation saveInBackground];
}


- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}

在我的方法中,我的开关改变状态:

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:@"HI" forKey:@"try"];
[currentInstallation saveInBackground];

PFPush *push = [[PFPush alloc] init];
[push setChannel:@"HI"];
[push setMessage:@"I am sending a push notification!"];
[push sendPushInBackground];

如下图,Parse收到我的推送,但是有0个"Pushes sent"。当我从 Parse 本身发送推送时只有 1 个订阅者,我的 iphone 确实收到了它。

所以基本上,我怎样才能让 Parse 将我首先从我的应用程序发送的推送通知发送回我的设备?我花了几个小时研究,所以请帮忙!!

正如 Paulw11 所述,在第一台设备上,您需要注册频道 "Hi"

 PFInstallation *currentInstallation = [PFInstallation currentInstallation];

 [currentInstallation addUniqueObject:@"Hi" forKey:@"channels"];
 [currentInstallation saveInBackground]; 

在第二台设备上,您有更改开关部分

 PFPush *push = [[PFPush alloc] init];
 [push setChannel:@"Hi"];
 [push setMessage:@"I am sending a push notification!"];
 [push sendPushInBackground];