繁体   English   中英

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

[英]Sent push notification to Parse, how to receive it in device

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

推送通知正在成功发送到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将我从我的应用程序发送的推送通知发送回我的设备? 我花了几个小时研究所以请帮助!!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM