1

我正在使用 iPhone SDK 4.0.1 创建 iPhone 应用程序 我的应用程序中有以下与来自媒体播放器的通知相关的代码行

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

在构建应用程序时,我将产品定位到 iphone 3.1 它构建良好并且在 iphone 4.0 设备上运行良好但是应用程序本身在 iphone 3.1.3 操作系统上运行时崩溃。它给出以下信息:

dyld: Symbol not found: _MPMoviePlayerLoadStateDidChangeNotification

引用自:/var/mobile/Applications/8572A1FF-488D-4F97-93DD-C06DBAD23B5B/OrangeDemo.app/OrangeDemo 预期在:/System/Library/Frameworks/MediaPlayer.framework/MediaPlayer 在 /var/mobile/Applications/8572A1FF- 488D-4F97-93DD-C06DBAD23B5B/OrangeDemo.app/OrangeDemo

我怎样才能避免这个错误。

4

1 回答 1

1

MPMoviePlayerLoadStateDidChangeNotification在 iOS 3.1.3 上不存在。您需要通过弱链接检测它的存在:

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

在 iOS 3.2 之前,您可以使用它MPMoviePlayerContentPreloadDidFinishNotification来检测电影何时完成预加载。如果您链接到较新的 SDK,该符号可能会生成弃用警告(如果您使用的是MPMoviePlayerLoadStateDidChangeNotification.)

请注意符号检查的语法:您必须进行比较,NULL而不是简单地将指针用作布尔值(即if (MPMoviePlayerLoadStateDidChangeNotification)if (&MPMoviePlayerLoadStateDidChangeNotification).)。编译器和动态加载器无法检测并正确处理这些形式,如果出现以下情况,将在 3.1.3 上崩溃他们被检测到。

于 2010-08-02T10:08:12.133 回答