• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung

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
 

SpecialFighter

Fießers Erstling
Registriert
25.04.12
Beiträge
131
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
    }