iOS 8的远程通知

问题描述:

在通知应用程序没有注册的儿子和徽章。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

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

(UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound) 
+0

我已经试过了。这没有改变。在通知我没有声音和徽章启用。 – dev1001 2014-09-23 19:55:51

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

也清楚地解释不叫registerForRemoteNotifications为iOS 8因为它已被弃用。

你好,请使用此代码,

 #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{ 

}