问题
I am using the framework GKAchievementNotification (https://github.com/typeoneerror/GKAchievementNotification) in my iOS 4.1+ app. This app is approved by Apple (is on app store) but seems to crash on iOS 4.3.3. The crash log is the following:
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
Seems like the framework is not correctly discarding GKNotificationBanner for iOS versions which it does not support (iOS prior to 5.0).
I am assuming the error lies in the following code, what do you think it wrong?
@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 is referensed in a few more places but always surrounded by #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
So how come it crashes? (And why only in release mode?)
Deployment target is 4.1. I read now that the run-time checking of if a class exist is only supported in 4.2. Could this be the problem?
回答1:
The #if
statement will be resolved at compile time and not at runtime and checks for the Base SDK version instead of the deployment version too. Since you are building with the latest iOS version, this code will always be executed, not matter which iOS version it is running on.
You can check the availability at runtime like:
id GKNotificationBannerClass = NSClassFromString(@"GKNotificationBanner");
if (GKNotificationBannerClass) {
....
回答2:
Think it could be related to me having a required linking to GameKit. Will change it to weak and submit it to App Store (for the third time).
来源:https://stackoverflow.com/questions/11696173/gknotificationbanner-on-ios-4-3-3