tags:

views:

535

answers:

2

I've compiled an app with IPhone base SDK 4.0, deployment target on iPhone OS 3.0. This app contains OS 4.0 new feature: local notification.

It works well on iPod 2G with OS 4.0; however it crashes every time the app start up on iPhone 1G with OS 3.0. It appears to be runtime reference error:

"dyld: Symbol not found: _OBJC_CLASS_$_UILocalNotification Referenced from: /var/mobile/Applications/73A3FAB1-63AE-4A71-8C6B-932142A728FE/Tapatalk X.app/Tapatalk X Expected in: /System/Library/Frameworks/UIKit.framework/UIKit"

If the UIKit framework is different between SDK3.0 & SDK4.0, why it doesn't report while compiling? How can I apply local notification feature on this app, while the app can still running on devices with OS3.0? Thanks.

A: 

If you use a 4.0 SDK feature and you want to support 3.0 devices, you need to check that the functionality exists before you use it.

If you're using a new class (as you are) something like the following should work:

Class localNotificationC = NSClassFromString(@"UILocalNotification");
if (localNotificationC) {
    UILocalNotification* localNotification = [[localNotificationC alloc] init];

    // do stuff

    [localNotification release];
}
else {
    // what to do with the 3.0 SDK
}

As for why the compiler doesn't tell you, well, you told the compiler that you were using the 4.0 SDK and those classes/methods work on 4.0.

Stephen Darlington
This error can occur before any user code has been run. I have one class referencing UILocalNotification, correctly wrapping the code in a block as you suggested. The app crashes with the above error, long before it gets to that class/method.
jamesh
Thanks for your answer. But my question is the same as jamesh. This runtime reference error was happened while the app start up, not until the "UILocalNotification" be invoked.
A framework that's new in iOS4 would certainly need to be weakly linked to your app. It wouldn't do any harm to do so against UIKit also, so it's certainly worth trying. I don't recall weak-linking against UIKit, though the "auto upgrade" to a Universal app may have done that for me. I'll check when I get back home.
Stephen Darlington
This is the correct answer. If you call any class methods of UILocalNotification, like 'alloc', you will get dynamic link errors before any of your code runs. If you acquire the class dynamically, as Stephen suggests, then you will by fine. Apple recommends this, and they certainly do *not* recommend weak-linking UIKit.
Darren
+2  A: 

This answer solved the problem for me:

That error is being triggered because you didn't weak-link the UIKit framework. The UIKit framework in iPhone OS 3.2 added the UISplitViewController, and if you link it in as normal your application will assume those symbols exist on 3.0, where they don't.

To weak-link a framework, find your application target in Xcode, inspect it, and go to the General tab. At the bottom of that tab should be a list of frameworks, with a column for Type. Change the Type for UIKit from Required to Weak and rebuild your application. That should take care of the runtime errors.

This seems safe to me, given that UIKit is always going to be on the devices we're targetting.

jamesh
Thanks. This seems working!