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 
相關問題