2014-09-29 1 views
12

Dies ist der Code für das i RemoteNotificationType verwendet:Wie aktualisiere ich Code mit enabledRemoteNotificationTypes, weil es "in iOS 8 nicht unterstützt wird"?

2014-09-29 15: 46:

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

Der Fehler i dies erhielt 47,416 Dummy [258: 21766] enabledRemoteNotificationTypes ist wird in iOS 8.0 und höher nicht unterstützt.

Wäre eine große Hilfe, wenn mir jemand die Lösung geben könnte.

+0

was über dieses http: // Stackoverflow .com/questions/25111644/detect-allow-benachrichtigungen-is-on-off-for-ios8? –

Antwort

17

Sie können diesen Code verwenden können:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(currentUserNotificationSettings)]) { 

    UIUserNotificationType types = [[[UIApplication sharedApplication] currentUserNotificationSettings] types]; 

    if (types == UIUserNotificationTypeNone) { 
     // Do something 
    } 

} else { 

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

    if (types == UIRemoteNotificationTypeNone) { 
     // Do something 
    } 
} 

Oder diese, wenn Sie nur den Benutzer überprüfen wollen, für Remote-Benachrichtigungen registriert:

if ([[UIApplication sharedApplication] respondsToSelector:@selector(isRegisteredForRemoteNotifications)]) { 

    BOOL isRegisteredForRemoteNotifications = [[UIApplication sharedApplication] isRegisteredForRemoteNotifications]; 

    if (isRegisteredForRemoteNotifications) { 
     // Do something 
    } 

} else { 

    UIRemoteNotificationType types = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

    if (types == UIRemoteNotificationTypeNone) { 
     // Do something 
    } 
} 
2

Bitte verwenden Sie folgende Methoden -

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 

oder

[[UIApplication sharedApplication] currentUserNotificationSettings] 

Benutzer-fähige Remote-Benachrichtigung und Benutzerbenachrichtigungseinstellungen in iOS 8.

16

Verwendung mit dieser Bedingung abrufen geben Unterstützung sowohl in iOS 7 und älteren iOS 8

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) 

NSUInteger rntypes; 
    if (!SYSTEM_VERSION_LESS_THAN(@"8.0")) { 
    rntypes = [[[UIApplication sharedApplication] currentUserNotificationSettings] types]; 
}else{ 
    rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 
}