iphone:在iOS 3.2上运行iOS 4.2的应用程序
问题描述:
我遇到问题。我开发了一个应用程序,这个应用程序在iOS 4.2上成功运行。现在我想在iOS 3.2上运行它,但应用程序在加载之前会崩溃。由于此行的代码:iphone:在iOS 3.2上运行iOS 4.2的应用程序
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMethod) name:UIApplicationWillEnterForegroundNotification object:nil];
我明白UIApplicationWillEnterForegroundNotification不支持iOS 3.2。但是当我使用时:
#ifdef __IPHONE_4_0
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDataAfterEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
#endif
该应用程序仍在该行代码中运行,并再次导致崩溃。我不知道我应该怎么做让3.2不运行该代码行。
非常感谢你
答
看看这个职位。可能更适合做这样或类似的事情。
+0
谢谢。但是我不能使用NSClassFromString,因为这是通知:UIApplicationWillEnterForegroundNotification仅适用于iOS 4及更高版本。 – haisergeant 2011-03-04 04:56:17
答
使用本
//的#if __IPHONE_OS_VERSION_MAX_ALLOWED> = 40000
NSLog(@"After Version 4.0");
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadDataAfterEnterForeground) name:UIApplicationWillEnterForegroundNotification object:nil];
//的#else
// #ENDIF
您的#ifdef被评估在编译时不是运行时。如果你将你的应用程序与ios 4.2 sdk链接,则条件满足。 – Kai 2011-03-04 09:26:30