ios - iOS 4.3.3 上的 GKNotificationBanner

标签 ios ios5 crash app-store

我在我的 iOS 4.1+ 应用程序中使用框架 GKAchievementNotification (https://github.com/typeoneerror/GKAchievementNotification)。此应用已获得 Apple 批准(在应用商店中),但似乎在 iOS 4.3.3 上崩溃。崩溃日志如下:

OS Version:      iPhone OS 4.3.3 (8J3)
Report Version:  104

Exception Type:  EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x00000001, 0xe7ffdefe
Crashed Thread:  0

Dyld Error Message:
  Symbol not found: _OBJC_CLASS_$_GKNotificationBanner
  Referenced from: /var/mobile/Applications/08289A0B-7AD3-4E37-B29F-A EDFE97B7ACA/PolarDefense.app/PolarDefense
  Expected in: /System/Library/Frameworks/GameKit.framework/GameKit
  in /var/mobile/Applications/08289A0B-7AD3-4E37-B29F-AEDFE97B7ACA/PolarDefense.app/PolarDefense
  Dyld Version: 191.3

对于它不支持的 iOS 版本(iOS 5.0 之前的版本),框架似乎没有正确丢弃 GKNotificationBanner。

我假设错误出在下面的代码中,你认为它错在哪里?

@implementation GKAchievementHandler(private)
- (void)displayNotification:(GKAchievementNotification *)notification {
 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
  if ([GKNotificationBanner class]) {
    [GKNotificationBanner showBannerWithTitle:notification.title 
                                      message:notification.message
                            completionHandler:^{
                                [self didHideAchievementNotification:notification];
                            }
     ];
  } else
 #endif
  {
    [_topView addSubview:notification];
    [notification animateIn];
  }
}
@end

GKNotificationBanner 在更多地方被引用,但总是被 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000 包围

那怎么会崩溃呢? (为什么只在 Release模式下?)

部署目标是 4.1。我现在读到,仅在 4.2 中支持运行时检查类是否存在。这可能是问题所在吗?

最佳答案

#if 语句将在编译时解析,而不是在运行时解析,并检查 Base SDK 版本而不是部署版本。由于您是使用最新的 iOS 版本构建的,因此无论运行在哪个 iOS 版本上,此代码都会始终执行。

您可以在运行时检查可用性,例如:

id GKNotificationBannerClass = NSClassFromString(@"GKNotificationBanner");
if (GKNotificationBannerClass) {
....

关于ios - iOS 4.3.3 上的 GKNotificationBanner,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11696173/

相关文章:

ios - 是否可以在 iOS Playground 中加载 Storyboard?

ios - swift - 保存 plist 字典而不覆盖键

ios - 将 UILabel 剪辑到 UIImageView

ios4 - NSDate 的 For 循环

ios - 使用带有自定义容器 View Controller 的滑动手势识别器时发生崩溃

ios - [UIView(CALayer Delegate)drawLayer:inContext:崩溃

ios - NSSortDescriptor 从 Swift 4 的核心数据中获取键

ios5 - 如何创建具有设备 UDID 而不是实际设备的 IPA 文件

ios - 在 iOS 上,哪个 View 元素应该类似于单选按钮?

iphone - 保存多个 map 注释 - 崩溃