我已经像这样配置了我的 Parse 接收 api:
[Parse setApplicationId:@"***" clientKey:@"***"];
[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
UIRemoteNotificationTypeAlert|
UIRemoteNotificationTypeSound];
和
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Store the deviceToken in the current installation and save it to Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
然后在我的代码中,我添加要订阅的 channel ,如下所示:
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
NSMutableArray *array = [NSMutableArray array];
for (Room *aRoom in rooms) {
NSString *strChannel = [NSString stringWithFormat:@"pr_%@", aRoom.roomId];
[array addObject:strChannel];
}
[currentInstallation setChannels:array];
在我的示例中, channel 是“pr_4”。
但是,当我在此 channel 上推送某些内容时,解析仪表板告诉我没有人订阅 channel “pr_4”。我不明白我做错了什么。
最佳答案
在您提供的代码中,您从未实际保存 PFInstallation
反对 parse.com。您应该添加:
[currentInstallation saveInBackground];
在您的代码末尾,在您设置 channel 之后。
旁注:您也可以使用方法
subscribeToChannelInBackground:
来自 PFPush
类,以便为设备订阅 channel :
subscribeToChannelInBackground:
Asynchronously subscribes the device to a channel of push notifications.
+ (void)subscribeToChannelInBackground:(NSString *)channel
Parameters
channel
The channel to subscribe to. The channel name must start with a letter and contain only letters, numbers, dashes, and underscores.
关于ios - 解析 iOS API - 添加 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22401711/