2014-09-19 11 views
10

Ich versuche, die application:didRegisterUserNotificationSettings: App Delegate-Methode zu implementieren, um zu versuchen, zu identifizieren, ob ich lokale Benachrichtigungen an den Benutzer in iOS 8 senden kann. Das Folgende ist die Art von was ich versuche zu erreichen , aber das ist offensichtlich die falsche Art, das zu tun.Wie man UIUserNotificationSettings-Typen abfragt

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings 
{ 

    if (notificationSettings.types /*How do i check which types are contained */) { 

     NSLog(@"Allowed"); 

    } else { 

     NSLog(@"Not Allowed"); 
    } 

} 

Antwort

22

Hier gehen Sie

if (notificationSettings.types == UIUserNotificationTypeNone) { 
     NSlog(@"Permission not Granted by user"); 
} 
else{ 
     NSlog(@"Permission Granted"); 
} 

Um eine bestimmte Einstellung abfragen:

BOOL allowsSound = (notifSettings.types & UIUserNotificationTypeSound) != 0; 
+1

Einfach, dank ... Ich werde die Antwort in 11 Minuten akzeptieren (wenn ich darf zu!) – Sammio2

+0

Immer willkommen !! Mate .. –

+0

Ok so, wie kann ich sagen, ob die Erlaubnis erteilt wird, aber nicht für Töne? Das funktioniert nicht: 'if (notifSettings.types == UIUserNotificationTypeSound)' – Sammio2

Verwandte Themen