2010-10-29 57 views
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]; 

}

回答

1

也許這是:

[[NSNotificationCenter defaultCenter] addObserver:self 
            selector:@selector(moviePlayBackDidFinish:) 
             name:MPMoviePlayerPlaybackDidFinishNotification 
             object:nil]; 

在線上方傳遞一個nil對象,並在您嘗試獲取它的方法:

MPMoviePlayerViewController *movie = [notification object];