【问题标题】:Sent push notification to Parse, how to receive it in device向 Parse 发送推送通知,如何在设备中接收它
【发布时间】:2015-03-07 11:48:55
【问题描述】:

我正在尝试发送和接收推送通知,因此,例如,当某个开关关闭时,另一部具有相同应用程序的手机会通过发送警报消息通知这已发生。

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

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

我按照 Parse 指南来配置这些,但我还是会发布我的代码: 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 将我首先从我的应用程序发送的推送通知发送回我的设备?我花了几个小时研究所以请帮忙!!

【问题讨论】:

  • 您正在推送到名为“HI”的频道,但您尚未在该频道中注册任何设备,因此发送了 0 次推送。
  • 您是否将安装注册到“HI”频道?喜欢currentInstallation.channels = @[ "HI" ];?并确保在完成[currentInstallation saveInBackground]; 后发送PFPush

标签: ios objective-c parse-platform push-notification xcode6


【解决方案1】:

正如 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];

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2017-01-08
  • 2011-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多