代码之家  ›  专栏  ›  技术社区  ›  LarsJK

如何在操作系统早于iOS4的设备上忽略UILocalNotification?

  •  1
  • LarsJK  · 技术社区  · 15 年前

    Class myClass = NSClassFromString(@"UILocalNotification");
    if (myClass) {
    //Local Notification code
    }
    

    但我的应用程序在启动时崩溃,错误代码如下:

    警告:无法读取的符号 “/Library/MobileSubstrate”/手机订阅.dylib" 找到: /var/移动/应用程序/FCFFFCB2-A60B-4A8D-B19B-C3F5DE93DAD2/MyApp.app/MyApp 预计在:

    数据格式化程序 “继续”。(呼叫dlopen不安全 在这个时候。) mi\u cmd\u stack\u list\u frames:不够 mi\u cmd\u stack\u list\u frames:不够 堆栈中的帧。

    2 回复  |  直到 15 年前
        1
  •  6
  •   Stefan Arentz    15 年前

    正确的方法是:

    Class localNotificationClass = NSClassFromString(@"UILocalNotification");
    if (localNotificationClass != nil) {
        // The UILocalNotification class is available
        UILocalNotification* localNotification =
            [[localNotificationClass alloc] initWith....];
    }
    

    你可以 使用 [UILocalNotificationClass alloc] 因为那会导致 链接错误 当您的代码加载到旧的iOS上,而该类不可用时。这正是你想要阻止的。

    顺便说一句:这些MobileSubstrate错误是你越狱时得到的:一个不可预测/未定义的开发平台:-)

        2
  •  -1
  •   LarsJK    15 年前

    不要介意。。 我用过:

    Class myClass = NSClassFromString(@"UILocalNotification");
    if (myClass) {
       //Local Notification code
       UILocalNotification *notification = [[myClass alloc] init];
    }
    

    而不是:

    Class myClass = NSClassFromString(@"UILocalNotification");
    if (myClass) {
      //Local Notification code
      UILocalNotification *notification = [[UILocalNotification alloc] init];
    }