after update to Xcode6, I got this code crash on IOS 7 with "Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
", can any one help with it
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)]){
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes: (UIUserNotificationTypeSound | UIUserNotificationTypeBadge | UIUserNotificationTypeAlert) categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
[[UIApplication sharedApplication] registerForRemoteNotifications];
}
else {
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}
EDIT : hi all, it's a runtime crash, not a compile time link error,
Exception Type: EXC_BREAKPOINT (SIGTRAP) Exception Codes: 0x0000000000000001, 0x00000000e7ffdefe Triggered by Thread: 0
Dyld Error Message: Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
and I was on Xcode 6.0 (6A313), So I should not use any #if to indicator iOS versions. And this code works fine on IOS 8 simulator, but crashes on IOS 7 devices
EDIT 2 :
Finally, this issue was fixed by these codes, I have mark the right answers below, thanks trojanfoe.
if ([application respondsToSelector:@selector(registerUserNotificationSettings:)])
{
Class userNotifyClass = NSClassFromString(@"UIUserNotificationSettings");
if(userNotifyClass != nil)
{
id notifyInstance = [userNotifyClass settingsForTypes:(UIUserNotificationTypeBadge | UIUserNotificationTypeAlert | UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:notifyInstance];
[application registerForRemoteNotifications];
}
}
else
{
int notifyType = (UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeSound);
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationType)notifyType];
}