unregisterForRemoteNotifications对iOS8不起作用 - 推送通知 [英] unregisterForRemoteNotifications doesn't work for iOS8 - Push Notification

查看:142
本文介绍了unregisterForRemoteNotifications对iOS8不起作用 - 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定从我的应用关闭提醒开关控制的通知。我在我的应用程序中添加了这些行,使其支持iOS 7和iOS 8,并且当我关闭推送通知时它正在工作。但是,当我决定打开开关并关闭应用程序时,当我再次打开它时,它又回到OFF而不是打开。因此,我必须转到设置 - >通知中心 - >我的应用程序并重新打开所有内容,因为它们已关闭...非常奇怪,当我在iOS 7上测试时,它正在运行但不适用于iOS 8.任何建议都表示赞赏。谢谢。

I decided to turn off my notification on "reminders" switch control from my app. I added those lines in my app to make it support both iOS 7 and iOS 8 and it is working when I switched off push notification. BUT when I decided to turn on the switch and closed the app,when I opened it again and it went back to OFF instead of being ON. So I have to go to Settings --> Notification Center --> "my app" and turn all the things back on because they are off... Very strange that when I test it on iOS 7 it is working but not for iOS 8. Any suggestion appreciated. Thanks.

- (IBAction)reminderSwitchToggled:(id)sender {

      UIApplication *application = [UIApplication sharedApplication];

      if ([sender isOn]) {

         #ifdef __IPHONE_8_0
             if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
                 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
                 [[UIApplication sharedApplication] registerUserNotificationSettings:settings];

             }
              else
         #endif
                 {
                   [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge| UIRemoteNotificationTypeAlert| UIRemoteNotificationTypeSound];
                 }

     } else {

         #ifdef __IPHONE_8_0
           if(NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {

               [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings
                                                                             settingsForTypes:
                                                                             (UIUserNotificationType)
                                                                             (UIUserNotificationTypeNone) 
                                                                             categories:nil]];

               [application unregisterForRemoteNotifications];

        }

          else
      #endif
          {
               [application unregisterForRemoteNotifications];

           }
   }
}


推荐答案

您应该在服务器端实现禁用推送通知。 Apple文档说你应该调用

You should implement disabling push notifications on the server side. Apple docs said that you should call

[[UIApplication sharedApplication] unregisterForRemoteNotifications];

仅当您不再在应用程序中提供通知时。 链接

only if you will not provide notifications in app any more. Link

另一方面,iOS8提供API来打开Settings.app,用户可以使用开关控制禁用应用程序的通知。用法示例:

In other hand, iOS8 provides API to open Settings.app, where user can disable notifications for your app using switch control. Usage sample:

if (&UIApplicationOpenSettingsURLString != NULL)
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];   

这篇关于unregisterForRemoteNotifications对iOS8不起作用 - 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆