我使用Parse PushNotification for iOS开发了应用程序,
我在我的应用中保留了通知开/关选项,
我想要做的是当用户点击通知关闭时我想禁用该设备的推送通知,或者当用户点击通知时我想为该设备启用推送通知。
我已经编写了这段代码,但它没有用,
if ([switcher isOn])
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
}else{
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
}
我是否需要编写更多代码?或者我犯了什么错误?
Plaese提前帮助和感谢。
答案 0 :(得分:-1)
我们应该在ios8中注册通知时进行一些更改,
if (SYSTEM_RUNS_IOS8_OR_LATER) {
if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
} else {
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}
}else{
UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound;
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes];
}