2014-09-26 1 views
8

Ich habe meinen Xcode auf Xcode 6.0.1 aktualisiert, jetzt ist keine Remote-Benachrichtigungsregistrierung für iOS 8-Geräte möglich. Es funktioniert gut für iOS 7-Gerät.Warum wird die App nicht für Push-Benachrichtigungen in iOS 8 registriert?

Ich habe den Code in AppDelegate hinzugefügt, wie unten erwähnt:

//-- Set Notification 
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
{ 
    UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIRemoteNotificationTypeBadge 
    |UIRemoteNotificationTypeSound|UIRemoteNotificationTypeAlert) categories:nil]; 
    [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; 

    NSLog(@"current notifications : %@", [[UIApplication sharedApplication] currentUserNotificationSettings]); 
} 
else 
{ 
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes: 
    (UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert)]; 
} 

Auch die aktuelle Meldung vorhanden ist, und es ist nicht gleich Null.

Und doch ist die unten Methode nicht aufgerufen wird:

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

Screenshot unten erklärt, dass ich bestimmte Optionen im Hintergrundmodus aktiviert haben:

enter image description here

Und die Benachrichtigung festgelegt ist in dem Gerät Einstellungen für meine App.

Antwort

16

Sie benötigen

[[UIApplication sharedApplication] registerForRemoteNotifications]; 

in Ihrem iOS8 Codepfad rufen, nachdem die Benutzerbenachrichtigungseinstellungen Registrierung.

+2

Vielen Dank helfen. Jetzt registriert sich die App erfolgreich für Push-Benachrichtigungen. – user1899840

13

Der folgende Code funktioniert in iOS 8.0 Xcode 6.0 oder höher und auch für die folgenden Versionen.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    //This code will work in iOS 8.0 xcode 6.0 or later 
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
    { 
     [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge) categories:nil]]; 

     [[UIApplication sharedApplication] registerForRemoteNotifications]; 
    } 
    else 
    { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes: (UIRemoteNotificationTypeNewsstandContentAvailability| UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)]; 
    } 

    return YES; 
} 
5

Überprüfen Sie die folgenden Schritte hoffen, dass es Ihnen

Schritte 1 In didFinishLaunchingWithOptions

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) 
{ 
    //ios8 ++ 
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) 
    { 
     UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil]; 
     [[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings]; 
    } 
} 
else 
{ 
    // ios7 
    if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerForRemoteNotificationTypes:)]) 
    { 
     [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)]; 
    } 
} 

Schritt 2

-(void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings // available in iOS8 
{ 
[application registerForRemoteNotifications]; 
} 
-(void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken 
{ 
    NSString * token = [NSString stringWithFormat:@"%@", deviceToken]; 
//Format token as you need: 
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""]; 
token = [token stringByReplacingOccurrencesOfString:@">" withString:@""]; 
token = [token stringByReplacingOccurrencesOfString:@"<" withString:@""]; 
NSLog(@"%@",token); 
} 
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{ 
// Handle your remote RemoteNotification 
} 

-(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error 
{ 
NSLog(@"Error:%@",error); 
}