2016-04-01 13 views
0

Kann jemand bitte einen Blick auf den folgenden Code und sagen Sie mir, warum die lokale Benachrichtigung nicht feuert. Ich führe die App in XCode aus und verwende die Debug-Option, um einen Hintergrundabruf zu simulieren, aber die lokale Benachrichtigung wird nicht ausgelöst.Lokale Benachrichtigung nicht mit Hintergrund Fetch

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler 
{ 
    NSLog(@"performFetchWithCompletionHandler"); 


UILocalNotification *localNotif = [[UILocalNotification alloc] init]; 

if (localNotif) { 
    localNotif.alertBody = @"Update demo text!"; 
    localNotif.alertAction = @"OK"; 
    localNotif.soundName = UILocalNotificationDefaultSoundName; 
    localNotif.fireDate = nil; 

    NSLog(@"Local Notification"); 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif]; 
} 

//Perform some operation 
completionHandler(UIBackgroundFetchResultNewData); 
} 

Antwort

3

Fragen Sie den Benutzer, um Push zu erlauben?

if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { 
     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound categories:nil]; 
     [application registerUserNotificationSettings:settings]; 
    } 
+0

Ahh ich nicht, dass es sein könnte. – ORStudios

+0

Perfekt, das war das Problem. Vielen Dank – ORStudios

1

Statt Geräteversion zu überprüfen, verwenden Sie folgenden Code, der RespondToSelector prüft:

if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) 
{ 
    [application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]]; 
} 
Verwandte Themen