Parse platform Parse.com在用户登录后注册推送通知

Parse platform Parse.com在用户登录后注册推送通知,parse-platform,Parse Platform,我知道要注册Parse.com推送通知,我必须在appdelegate文件中进行设置。但我想知道在用户登录viewcontroller类后是否可以覆盖通道并注册到多个通道 您应该能够通过执行以下操作来实现 if(![currentInstallation channels]) { [currentInstallation setChannels:@[@"WHATEVER1", @" WHATEVER2"]]; NSLog(@"Set Channel"); } else { [

我知道要注册Parse.com推送通知,我必须在appdelegate文件中进行设置。但我想知道在用户登录viewcontroller类后是否可以覆盖通道并注册到多个通道

您应该能够通过执行以下操作来实现

if(![currentInstallation channels]) {

    [currentInstallation setChannels:@[@"WHATEVER1", @" WHATEVER2"]];
    NSLog(@"Set Channel");
} else {

[currentInstall addUniqueObject:@"objectone" forKey:@"channels"];
[currentInstall addUniqueObject:@"objecttwo" forKey:@"channels"];
} [currentInstall saveInBackgroundWithBlock:(BOOL succeeded, NSError *error) {

if(!error){
    NSLog(@"subscribed user to both channels");
} else {
    NSLog(@"error subscribing to both channels: %@", error);
}
}];

您只需在应用程序中的任何位置运行UIApplication的共享实例,然后调用注册方法。像这样:

    let application = UIApplication.sharedApplication()
    let settings = UIUserNotificationSettings(forTypes: [.Alert, .Badge], categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()
这将显示“推送通知”对话框,询问他们是否希望允许通知,然后调用相应的应用程序委派方法,该方法可以是
didfailtoregister for remotenotificationswitherror
didRegisterForRemoteNotificationsWithDeviceToken


如果您在模拟器上而不是在实际设备上进行测试,则将始终调用错误

我想你误解了这个问题。他想知道是否可以在AppDelegate文件之外的其他地方注册频道。ie仅在用户登录后注册频道,而不是在应用程序启动时注册。