2014-09-29 8 views
12

questo è il codice che ho usato per la RemoteNotificationType:Come aggiornare il codice utilizzando enabledRemoteNotificationTypes perché "non è supportato in iOS 8"?

NSUInteger rntypes = [[UIApplication sharedApplication] enabledRemoteNotificationTypes]; 

L'errore ho ottenuto era:

2014-09-29 15: 46: 47,416 Dummy [258: 21766] enabledRemoteNotificationTypes viene non supportato in iOS 8.0 e versioni successive.

Sarebbe di grande aiuto se qualcuno potesse darmi la soluzione.

+0

che dire di questo http: // StackOverflow .com/domande/25111644/Detect-allow-notifiche-is-on-off-for-iOS 8? –

risposta

17

È inoltre possibile utilizzare questo codice:

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 
    } 
} 

O questo uno se desideri solo controllare l'utente è registrato per le notifiche a distanza:

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

Si prega di usare dopo i metodi -

[[UIApplication sharedApplication] isRegisteredForRemoteNotifications] 

o

[[UIApplication sharedApplication] currentUserNotificationSettings] 

per recuperare le impostazioni di notifica e di notifica all'utente remoto di utenti abilitati in iOS 8.

16

Utilizzare con questa condizione per dare supporto sia in iOS 7 che iOS precedente 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]; 
}