在App中更改分析推送通知当前频道

时间:2016-01-14 14:35:44

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

我使用解析sdk将当前用户频道添加到工作代码中 但我想在应用示例中更改当前频道(在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];
}

我的视图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];

}

但不要将当前用户频道Frist更改为Second。 我尝试了一切但不改变我需要帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

您是否尝试将用户取消订阅旧频道,然后将其订阅到新频道?

这是我订阅和取消订阅频道的代码,它运行正常:

PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation removeObject:@"type1user" forKey:@"channels"];
//subcribing to the second channel
[currentInstallation addUniqueObject:@"type2user" forKey:@"channels"];
[currentInstallation saveInBackground];

以及取消订阅和订阅第二频道:

list