У меня есть следующий код в моем приложении - и я вижу некоторые сбои на iOS 7 в строке с комментарием.
+ (void)registerDeviceForRemoteNotifications {
#if !TARGET_IPHONE_SIMULATOR
if ([[KOAAuthenticator sharedAuthenticator] currentUser] != nil) {
UIApplication *sharedApplication = [UIApplication sharedApplication];
#ifdef __IPHONE_8_0
[sharedApplication registerForRemoteNotifications]; // <--- CRASH HERE
#else
[sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
#endif
}
#endif
}
Crashlytics говорит: -[UIApplication registerForRemoteNotifications]: unrecognized selector sent to instance 0x157d04290
как это возможно? Этот код нельзя вызывать на iOS 7, правильно?
EDIT: решение
+ (void)registerDeviceForRemoteNotifications {
#if !TARGET_IPHONE_SIMULATOR
if ([[KOAAuthenticator sharedAuthenticator] currentUser] != nil) {
UIApplication *sharedApplication = [UIApplication sharedApplication];
#ifdef __IPHONE_8_0
if ([sharedApplication respondsToSelector:@selector(registerForRemoteNotifications)]) {
[sharedApplication registerForRemoteNotifications];
} else {
[sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
}
#else
[sharedApplication registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert];
#endif
}
#endif
}