1

我有一个iOS应用程序,我需要从我的应用程序设置页面启用/禁用推送通知;我用下面的代码,以使推送通知如何启用/禁用从应用程序的推送通知iOS 8

[[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
     (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 

和这个代码以禁用推送通知

[[UIApplication sharedApplication] unregisterForRemoteNotifications]; 

,但它不是与iOS 8工作的i-接收上调试以下消息

enabledRemoteNotificationTypes is not supported in iOS 8.0 and later 

任何人都可以告诉我一个解决方案来打开/关闭通知中心的应用程序的状态从应用程序?

+0

请帮忙;需要任何人给我的指导 – Sonic 2014-11-23 22:11:22

回答

-2

registerForRemoteNotificationTypes方法是deprecated。 Apple列出了您应该使用的新方法(registerForRemoteNotifications)。

很难说你的问题是关于你得到的警告,还是关于它的功能如你所期望的那样。

+0

我的问题是关于从我的应用程序的设置视图启用/禁用推送通知的正确方法 – Sonic 2014-11-22 21:22:04

0

注册:

UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert | 
                 UIUserNotificationTypeBadge | 
                 UIUserNotificationTypeSound); 

UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes categories:nil]; 

[[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 

注销:

[[UIApplication sharedApplication] unregisterForRemoteNotifications]; 
0

我试着用下面的方式&它的工作..

#ifdef __IPHONE_8_0 
    //Right, that is the point 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge 
|UIRemoteNotificationTypeSound 
|UIRemoteNotificationTypeAlert) categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
#else 
    //register to receive notifications 
    UIRemoteNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound; 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:myTypes]; 
#endif 

添加以下方法适用于iOS 8.0

#ifdef __IPHONE_8_0 
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 
{ 
    //register to receive notifications 
    [application registerForRemoteNotifications]; 
} 

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler 
{ 
    //handle the actions 
    if ([identifier isEqualToString:@"declineAction"]){ 
    } 
    else if ([identifier isEqualToString:@"answerAction"]){ 
    } 
} 
#endif 
相关问题