![](/img/trans.png)
[英]iPhone CLLocation Simulator didUpdateToLocation never called
[英]iPhone: UIApplicationWillResignActiveNotification never called
我在視圖控制器中播放視頻。 當用戶點擊硬件主頁按鈕並且視頻當前正在播放時,應用程序在模擬器中以EXC_BAD_ACCESS
崩潰。
我讀到我應該使用applicationWillResignActive
消息來停止播放視頻,以解決崩潰問題。 所以我試圖通知通知中心,但我的選擇器永遠不會被調用。 我究竟做錯了什么?
以下代碼位於我的媒體播放器視圖控制器中:
- (void) playMedia {
NSURL *mediaUrl = [NSURL fileURLWithPath:tmpFilePath isDirectory:FALSE];
player = [[MPMoviePlayerViewController alloc] initWithContentURL:mediaUrl];
player.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
player.view.frame = self.view.frame;
[self.view addSubview:player.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActive:)
name:UIApplicationWillResignActiveNotification
object:nil];
[player.moviePlayer play];
}
- (void)applicationWillResignActive:(NSNotification *)notification {
// never gets called!
NSLog(@"resign active");
[player.moviePlayer stop];
}
請注意,如果您在應用程序的Info.plist中將UIApplicationExitsOnSuspend
鍵設置為true,則在用戶點擊主頁按鈕時不會調用applicationWillResignActive
方法。
不知道為什么那個人不適合你,但我正在使用
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopAction:) name:UIApplicationDidEnterBackgroundNotification object:nil];
在音頻播放器/錄音機中取得成功。
可能嘗試實施
- (void)applicationWillResignActive:(NSNotification *)notification { }
在應用程序委托中,看看它是否調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.