I am using local notifications in a app I'm making.
I use this:
Class myClass = NSClassFromString(@"UILocalNotification");
if (myClass) {
//Local Notification code
}
To avoid using UILocalNotifications when not supported.
But my app crashes on launch with this error code:
warning: Unable to read symbols for "/Library/MobileSubstrate/MobileSubstrate.dylib" (file not found). dyld: Symbol not found: _OBJC_CLASS_$_UILocalNotification Referenced from: /var/mobile/Applications/FCFFFCB2-A60B-4A8D-B19B-C3F5DE93DAD2/MyApp.app/MyApp Expected in: /System/Library/Frameworks/UIKit.framework/UIKit
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.) mi_cmd_stack_list_frames: Not enough frames in stack. mi_cmd_stack_list_frames: Not enough frames in stack.
开发者_StackOverflow中文版How can i prevent this?
The proper way to do this is:
Class localNotificationClass = NSClassFromString(@"UILocalNotification");
if (localNotificationClass != nil) {
// The UILocalNotification class is available
UILocalNotification* localNotification =
[[localNotificationClass alloc] initWith....];
}
You can not use [UILocalNotificationClass alloc]
because that will cause Link Errors when your code is loaded on an older iOS where the class is not available. And that is exactly what you are trying to prevent.
BTW: Those MobileSubstrate errors are what you get when you jailbreak your phone: an unpredictable/undefined development platform :-)
Never mind.. I used:
Class myClass = NSClassFromString(@"UILocalNotification");
if (myClass) {
//Local Notification code
UILocalNotification *notification = [[myClass alloc] init];
}
instead of:
Class myClass = NSClassFromString(@"UILocalNotification");
if (myClass) {
//Local Notification code
UILocalNotification *notification = [[UILocalNotification alloc] init];
}
and it worked!
Edited to clearify!
精彩评论