2016-06-20 64 views
0

我在appDelegate中的application:didFinishLaunchingWithOptions:方法中有以下代碼。通知在iOS9中出現兩次

if([application respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
    UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 

    [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 
} 

我做錯了什麼?

回答

0

你好,你應該在application:didFinishLaunchingWithOptions:

if ([application respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) 
{ 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

    [application registerForRemoteNotifications]; 
} 
else 
{ 
    [application registerForRemoteNotificationTypes: 
    (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound)]; 
} 
+0

仍然得到通知,試試這個的兩倍。 isRegisteredForRemoteNotifications如何產生影響? – Chinmay