我有使用解析 SDK 添加到当前用户 channel 的工作代码 但我想更改应用程序示例中的当前 channel (在 Viewcontroller.m 中)
这里是我的代码
Appdelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
sleep(2);
[Parse setApplicationId:@"sdfsdfsdfsdfsdf"
clientKey:@"sdfsdfsdfsdf"];
// Register for Push Notitications
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.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}
我的 View controller.m文件
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
currentInstallation.channels = @[@"Second"];
[currentInstallation saveInBackground];
}
但不要将当前用户 channel “Frist”更改为“Second”。 我尝试了一切,但不改变,我需要帮助。谢谢!
最佳答案
您是否尝试取消用户对旧 channel 的订阅,然后再订阅新 channel ?
这是我订阅和取消订阅 channel 的代码,它工作正常:
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation addUniqueObject:@"type1user" forKey:@"channels"];
[currentInstallation saveInBackground];
以及取消订阅和订阅第二个 channel :
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation removeObject:@"type1user" forKey:@"channels"];
//subcribing to the second channel
[currentInstallation addUniqueObject:@"type2user" forKey:@"channels"];
[currentInstallation saveInBackground];
关于ios - 更改应用程序中解析推送通知的当前 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34792193/