0
我玩用MPMovieplayerViewController一部電影,我想註冊通知短片停止時...我用下面的代碼使用NSNotification但電影停止時我的應用程序崩潰...我有使用NSNotification以前相同的方式執行罰款..任何想法,我在做什麼錯?註冊NSNotification崩潰我的應用程序?
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
NSLog(@"moviePlayBackDidFinish");
MPMoviePlayerViewController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:1.0];
}
-(void)playbackFinishedCallback:(NSNotification *)notification{
MPMoviePlayerViewController *movie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:movie];
NSLog(@"playbackFinishedCallback:");
[self performSelector:@selector(stopRecording) withObject:nil afterDelay:1.0];
}
在我AppDelegate類
我已經註冊了這樣
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[navigationController release];
[window release];
[super dealloc];
}