views:

246

answers:

1

I'm creating iPhone application using iPhone SDK 4.0.1 I've the following lines of code in my application related to notifications from media player

[[NSNotificationCenter defaultCenter]
        addObserver:self
           selector:@selector(moviePreloadDidFinish:)
               name:MPMoviePlayerLoadStateDidChangeNotification
             object:m_player];

When building the app, I'm targeting the the product to iphone 3.1 Its building fine and running well on iphone 4.0 device But the app itself is crashing when running on iphone 3.1.3 OS. Its giving following message:

dyld: Symbol not found: _MPMoviePlayerLoadStateDidChangeNotification

Referenced from: /var/mobile/Applications/8572A1FF-488D-4F97-93DD-C06DBAD23B5B/OrangeDemo.app/OrangeDemo Expected in: /System/Library/Frameworks/MediaPlayer.framework/MediaPlayer in /var/mobile/Applications/8572A1FF-488D-4F97-93DD-C06DBAD23B5B/OrangeDemo.app/OrangeDemo

How can I avoid this error.

+1  A: 

MPMoviePlayerLoadStateDidChangeNotification doesn't exist on iOS 3.1.3. You need to detect its presence via weak linking:

if (&MPMoviePlayerLoadStateDidChangeNotification != NULL) {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePreloadDidFinish:) name:MPMoviePlayerLoadStateDidChangeNotification object:m_player];
}

Prior to iOS 3.2 you can use MPMoviePlayerContentPreloadDidFinishNotification to detect when the movie has finished preloading. That symbol may generate a deprecation warning if you are linking against a newer SDK (as you are if you're using MPMoviePlayerLoadStateDidChangeNotification.)

Note the syntax of the symbol check: you must compare against NULL rather than simply using the pointer as the boolean (i.e. if (MPMoviePlayerLoadStateDidChangeNotification) or if (&MPMoviePlayerLoadStateDidChangeNotification).) The compiler and dynamic loader are not able to detect and properly handle those forms, and will crash on 3.1.3 if they are detected.

Jonathan Grynspan
As a slight clarification, what you describe here is how to detect the presence of a method. He will still need to weak link by finding the application target in Xcode, inspecting it, and going 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 MediaPlayer from Required to Weak.
Brad Larson
You shouldn't need to switch the type of the framework, as it has been included since iOS 2.0.
Jonathan Grynspan