解析iOS API - 添加频道

Plo*_*lot 1 channel push-notification ios parse-platform

我已经配置了我的Parse接收api,如下所示:

[Parse setApplicationId:@"***" clientKey:@"***"];

[application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|
 UIRemoteNotificationTypeAlert|
 UIRemoteNotificationTypeSound];
Run Code Online (Sandbox Code Playgroud)

- (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];
}
Run Code Online (Sandbox Code Playgroud)

然后在我的代码中,我添加了要订阅的频道,如下所示:

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];
Run Code Online (Sandbox Code Playgroud)

在我的例子中,频道是"pr_4".

当我在这个频道上推送一些东西时,解析仪表板告诉我没有人订阅频道"pr_4".我不明白我做错了什么.

rdu*_*and 5

在您提供的代码中,您实际上从未将PFInstallation对象保存到parse.com.你应该添加:

[currentInstallation saveInBackground];
Run Code Online (Sandbox Code Playgroud)

在您设置频道后,在代码的最后.


侧面说明:您还可以使用该方法subscribeToChannelInBackground:PFPush类以设备订阅频道:

subscribeToChannelInBackground:

异步订阅设备到推送通知的通道.

+ (void)subscribeToChannelInBackground:(NSString *)channel

参数

渠道

订阅频道.通道名称必须以字母开头,并且只包含字母,数字,短划线和下划线.