ios - 在 Parse 上删除用户推送通知 iOS

标签 ios objective-c parse-platform push

您如何使用 parse 将用户从接收推送通知中移除?例如,如果用户转到他的设置(在应用程序内)并决定关闭推送通知...

我认为删除他们的“全局” channel 就可以解决问题,但用户似乎仍在使用它们。想想看,如果这确实有效,他们仍然能够将推送发送到与用户关联的其他 channel 。无论如何,解决这个问题的方法是什么?

我尝试过这两种方法:

currentInstallation.channels = @[ @"global" ]; //enable

currentInstallation.channels = @[]; //disable

[currentInstallation addUniqueObject:@"global" forKey:@"channels"]; //enable

[currentInstallation removeObject:@"global" forKey:@"channels"]; //disable

然后我尝试通过 Parses Web UI 为“每个人”发送一个推送,并且只为那些匹配“全局” channel 的人发送一个推送。不幸的是,用户仍然收到了它。

我几乎遵循了 Parse iOS 推送设置教程。这就是我的实现的样子:

-(void)displayPushAuthRequest{
    UIApplication *app = [UIApplication sharedApplication];
    if([app respondsToSelector:@selector(registerUserNotificationSettings:)] && [app respondsToSelector:@selector(registerForRemoteNotifications)]){
        //ios 8
        UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                        UIUserNotificationTypeBadge |
                                                        UIUserNotificationTypeSound);
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                                 categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
        [[UIApplication sharedApplication] registerForRemoteNotifications];
    }
    {
        //ios 7
        UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];

    }

}


- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
    // Save the settings locally (first time)
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"didRegisterForRemoteNotifications"];
    [[NSUserDefaults standardUserDefaults]synchronize];

    // Store the deviceToken in the current installation and save it to Parse.
    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    [currentInstallation setDeviceTokenFromData:deviceToken];
    currentInstallation.channels = @[ @"global" ];
    [currentInstallation saveInBackground];

}

最佳答案

你可以试试下面的方法吗

PFInstallation *currentInstallation = [PFInstallation  currentInstallation];
currentInstallation.channels = [NSArray array];
[currentInstallation saveEventually];

关于ios - 在 Parse 上删除用户推送通知 iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28948973/

相关文章:

iphone - 如何设置字体大小以填充 UILabel 高度?

ios - 如何在预定义的矩形中显示图像的缩放部分?

javascript - 无法在 React Native 中发现我的语法错误?

ios - 如何使用 SoundCloud API 获取我所有的播放列表

android - 从 BroadcastReceiver 调用 Activity 内部的方法

IOS 框架本地化不起作用

ios - 快速将视频 NSData 写入图库

objective-c - 从 NSTokenField 获取 token

ios - 使用指针搜索 Parse 返回错误 "pointer field needs a pointer value"

database - 一对多的可扩展性和获取许多的效率 - parse.com