我正在尝试发送和接收推送通知,因此,例如,当某个开关关闭时,另一部具有相同应用程序的手机会通过发送提醒消息通知发生这种情况。
推送通知正在成功发送到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“推送已发送”。当我从Parse本身发送推送时,只有1个用户,我的iphone确实收到了它。
所以基本上,我怎样才能让Parse将我从我的应用程序发送的推送通知发送回我的设备?我花了几个小时研究所以请帮助!!
答案 0 :(得分:0)
如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];