ios - 解析 iOS API - 添加 channel

标签 ios push-notification parse-platform channel

我已经像这样配置了我的 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/

相关文章:

objective-c - 改变 UIStepper 的大小

ios - Firebase for iOS 内部框架

ios - 如何在 Swift(iOS、Xcode)中将 NSDictionary 转换为 Json 字符串?

javascript - 使用 jQuery JavaScript/任何插件推送通知

ios - 谁能帮助我理解为什么我的 PFUser 子类在 save() 上崩溃?

java - 在 ListView 中使用 android studio 从 Parse 中的指针检索数据

java - Android ProGuard 问题与 Parse 1.3.5 jar

ios - 类型 '[String]' 的值没有成员 'lastObject'

ios - 推送通知 Json 中 "Content-available"的用途?

android - 在 OneSignal 中打开通知点击应用程序