ios - 更改应用程序中解析推送通知的当前 channel

标签 ios objective-c xcode parse-platform push-notification

我有使用解析 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/

相关文章:

iphone - Cocos2D 和排行榜

ios - 通过引用访问实例变量安全吗?

ios - 从子调用父方法?

ios - map 中的随机 MKPointAnnotation

xcode - 存档验证失败并出现错误

ios - Xcode 6.3.2重构->重命名不起作用

ios - 当我在 iOS 中输入空的 AlertView 文本字段时,不应关闭 AlertViewController

ios - iOS-系统声音未播放

iphone - ios/xcode 使文本书写方向从右到左

ios - 有没有办法使用 SwiftUI 将事件添加到日历?