开发者

Weak linking to support previous iOS versions

I'm trying to support older iOS versions in my app. I initially thought I only have to set those frameworks to "weak linking" that are not present in the older OS, e.g. the iAd framework. And then make sure that I don't call unsupported APIs in the code. However, when I try to run the app (which is compiled with the most recent framework) in the old simulator, it crashes during startup with a message similar to

18/07/2010 11:07:29 UIKitApplication:xxxxx[0xe006][5729]    dyld: Symbol not found: _OBJC_CLASS_$_NSAssertionHandler
18/07/2010 11:07:29 UIKitApplication:xxxxx[0xe006][5729]      Referenced from: xxxxx/Applications/23CE4978-D25F-4DB4-A486-0730EBBB501B/xxxxx.app/xxxxx
18/07/2010 11:07:29 UIKitApplication:xxxxx[0xe006][5729]      Expected in: /Xcode3.1.4/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.3.sdk/System/Library/Frameworks/Foundation.framework/Foundation
18/07/2010 11:07:29 UIKitApplication:xxxxx[0xe006][5729]     in xxxxx/Applications/23CE4978-D25F-4DB4-A486-0730EBBB501B/xxxxx.app/xxxxx

After setting all frameworks to weak linking, I still get an error message:

18/07/2010 11:33:32 UIKitApplication:xxxxx[0xc4a7][8204]    dyld: Symbol not found: __objc_empty_vt开发者_如何学Cable
18/07/2010 11:33:32 UIKitApplication:xxxxx[0xc4a7][8204]      Referenced from: xxxxx/Applications/23CE4978-D25F-4DB4-A486-0730EBBB501B/xxxxx.app/xxxxx
18/07/2010 11:33:32 UIKitApplication:xxxxx[0xc4a7][8204]      Expected in: /usr/lib/libobjc.A.dylib

What am I doing wrong?


I think I found the solution (please can someone confirm this?):

You cannot use the simulator to test if your apps run with a previous iOS version. It only works on the device, according to Apple:

iPhone OS Note: Mac OS X v10.6 does not support using iPhone Simulator SDKs prior to version 3.0. In addition, when building with the simulator SDKs, the binary runs only on the same OS version as the SDK, not on earlier or later versions.

This seems really dull. How am I supposed to test backwards compatibility without having one physical iPhone for each SDK version? Not good.


You can't use the new class directly if you want to support old platforms. Instead, you use NSClassFromString like so:

class myClass = NSClassFromString(@"NSCoolNewClass");
if (myClass) 
    //do stuff
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜