我在我正在制作的应用中使用本地通知.
我用这个:
Class myClass = NSClassFromString(@"UILocalNotification");
if (myClass) {
//Local Notification code
}
Run Code Online (Sandbox Code Playgroud)
在不受支持时避免使用UILocalNotifications.
但我的应用程序在启动时因此错误代码而崩溃:
警告:无法读取"/Library/MobileSubstrate/MobileSubstrate.dylib"(未找到文件)的符号.dyld:未找到符号:_OBJC_CLASS _ $ _ UILocalNotification引自:/var/mobile/Applications/FCFFFCB2-A60B-4A8D-B19B-C3F5DE93DAD2/MyApp.app/MyApp预期:/System/Library/Frameworks/UIKit.framework/UIKit
数据格式化程序暂时不可用,将在"继续"后重试.(此时调用dlopen不安全.)mi_cmd_stack_list_frames:堆栈中没有足够的帧.mi_cmd_stack_list_frames:堆栈中没有足够的帧.
我该如何防止这种情况?
正确的方法是:
Class localNotificationClass = NSClassFromString(@"UILocalNotification");
if (localNotificationClass != nil) {
// The UILocalNotification class is available
UILocalNotification* localNotification =
[[localNotificationClass alloc] initWith....];
}
Run Code Online (Sandbox Code Playgroud)
您无法使用,[UILocalNotificationClass alloc]因为当您的代码加载到类不可用的旧iOS时,这将导致链接错误.而这正是你想要阻止的.
顺便说一句:那些MobileSubstrate错误是你越狱手机时得到的:一个不可预测/未定义的开发平台:-)
| 归档时间: |
|
| 查看次数: |
975 次 |
| 最近记录: |