更新Xcode6後,當沒有找到符號,我得到這個代碼墜毀上IOS 7「Symbol not found: _OBJC_CLASS_$_UIUserNotificationSettings
」,任何一個可以幫助它使用-ObjC/-all_load連接標誌
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];
}
編輯: 喜總之, 這是一個運行時的崩潰,而不是一個編譯時鏈接錯誤,
異常類型:EXC_BREAKPOINT(SIGTRAP) 異常代碼:0x0000000000000001,0x00000000e7ffdefe 通過主題:0觸發
dyld的錯誤消息: 找不到符號:_OBJC_CLASS _ $ _ UIUserNotificationSettings
和我在的Xcode 6.0(6A313),所以我不應該用任何#如果到指標的iOS版本。而這個代碼適用於iOS模擬器8罰款,但崩潰在IOS 7設備
編輯2:
最後,這個問題是由這些代碼固定的,我有以下標記正確的答案,謝謝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];
}
通過 「代碼崩潰」 你的意思是 「鏈接錯誤」? – trojanfoe 2014-09-23 08:00:58
@ Daij-Djan抱歉,我不明白你的意思。 – trojanfoe 2014-09-23 08:08:44
你在ARM64上測試嗎? – Andy 2014-09-23 13:20:18