2014-09-23 75 views
-1

在通知應用程序沒有註冊的兒子和徽章。iOS 8的遠程通知

這是我的代碼:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:  (NSDictionary *)launchOptions 
{ 
    //-- Set Notification 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.000000) { 
     UIUserNotificationSettings * settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } else { 
     //[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 
     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 

有人有一個解釋?謝謝

+1

有什麼不好?你能指望什麼? – vikingosegundo 2014-09-23 19:41:41

+0

看看' - [NSProcessInfo isOperatingSystemAtLeastVersion:]'。 – wjl 2014-09-23 19:47:49

+0

謝謝你的回答 – dev1001 2014-09-24 14:23:37

回答

-1

在iOS的版本8,你忘了括號

(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) 
+0

我已經試過了。這沒有改變。在通知我沒有聲音和徽章啓用。 – dev1001 2014-09-23 19:55:51

1

的iOS 8需要推送通知委託方法的一些變化和this link

也清楚地解釋不叫registerForRemoteNotifications爲iOS 8因爲它已被棄用。

0

你好,請使用此代碼,

 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 
     if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) { 
      UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 
      [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 
     } else { 
      [[UIApplication sharedApplication] 
      registerForRemoteNotificationTypes: 
      (UIRemoteNotificationTypeAlert | 
       UIRemoteNotificationTypeBadge | 
       UIRemoteNotificationTypeSound)]; 
     } 
    #else 
     [[UIApplication sharedApplication] 
     registerForRemoteNotificationTypes: 
     (UIRemoteNotificationTypeAlert | 
      UIRemoteNotificationTypeBadge | 


UIRemoteNotificationTypeSound)]; 
#endif 

和委託方法,

#pragma mark - Push Notification 

- (void)application:(UIApplication *)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { 

    // Prepare the Device Token for Registration (remove spaces and < >) 
    NSString *TokenID = [[[[deviceToken description] 
          stringByReplacingOccurrencesOfString:@"<"withString:@""] 
          stringByReplacingOccurrencesOfString:@">" withString:@""] 
         stringByReplacingOccurrencesOfString: @" " withString: @""]; 


    [ApplicationPreferences setTokenId:TokenID]; 
    if (DEBUG_MODE) { 
     NSLog(@"device token - %@",[NSString stringWithFormat:@"Device Token = %@",TokenID]); 
     NSUUID *oNSUUID = [[UIDevice currentDevice] identifierForVendor]; 
     NSLog(@"Vendor token - %@",[NSString stringWithFormat:@"Device Token = %@",[oNSUUID UUIDString]]); 
    } 

} 

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

- (void)application:(UIApplication *)app didFailToRegisterForRemoteNotificationsWithError:(NSError *)err { 
    if (DEBUG_MODE) { 
     NSLog(@"Push Error- %@",[NSString stringWithFormat: @"Error: %@", err]); 
    } 
} 
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{ 

}