• Wieder einmal haben uns unsere Apfeltalker tolle Fotos zur Abstimmung eingesandt. Welches ist Euer Favorit? Stimmt mit ab! Hier geht es zur Abstimmung --> Klick
  • Es ist bereits Apfeltalk-Tradition und wir möchten sie auch in diesem Jahr fortsetzen: Unser Apfeltalk-Weihnachtslogo-Wettbewerb hat begonnen! Gestaltet für uns das Weihnachtsbanner, das im Monat Dezember bis zum Weihnachtsfest unsere Webseite schmücken soll. Lasst Eurer Kreativität freien Lauf! Hier geht es zum Wettbewerb --> Klick

Frage um Erlaubnis für Local Notification

AppDev04

Gala
Registriert
19.10.14
Beiträge
48
Hallo

Für meine kleine App plane ich eine Ergänzung in Form von Local Notification. Den Code für die Notification habe ich schon geschrieben und er funktioniert soweit auch:

Code:
    // Create new UILocalNotification object.
    UILocalNotification *localNotification = [[UILocalNotification alloc] init];
   
    // Set the date and time of the notification.
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
   
    // Set the message body of the notification.
    localNotification.alertBody = @"It works, Yeeeeh";
   
    //Sound
    localNotification.soundName = @"sound.mp3";
   
    // Set the time zone of the notification.
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
   
    // Perform the notification.
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];


Jetzt möchte ich beim Start der App, dass überprüft wird, ob Notification erlaubt ist. Wenn nicht, dass dann in Form einer AlertView danach gefragt wird. Ein Beispiel habe ich schon gefunden, funktioniert leider nicht:

Code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   
    if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]) {
        [[UIApplication sharedApplication] registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil]];
    }
   
    return YES;
}

PS: Die App ist für iOS 8.0 und höher ausgerichtet
 
in der AppDelagte ergänzen:

Code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        if(UIApplication.instancesRespondToSelector(Selector("registerUserNotificationSettings:"))) {
            UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: .Alert | .Badge, categories: nil))
        }
        return true
    }