Question

Considering real life situation, suppose i have assigned some work to 3 people(say Person A, Person B, Person C), instead of waiting for them to complete a task each, i want that when each Person completes all assigned tasks, he/she will notify me distinctly. So that i can take further decision based on his/her task.

I want to implement this situation in code, with out using separate thread and delegates, i mean using NSNotification.

How can i do this stuff with programming, can u solve above situation using code (iPhone SDK-Objective C)?

Was it helpful?

Solution

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer.moviePlayer];


- (void)myMovieFinishedCallback:(NSNotification*)aNotification
{    
    // Release the movie instance created in playMovieAtURL

    MPMoviePlayerController *theMovie = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIDeviceOrientationDidChangeNotification
                                                  object:theMovie]; 

    [theMovie stop];
    [theMovie.view removeFromSuperview];

} 

Like this you can use the NSNotification. Hope you understand.

OTHER TIPS

As long as you are not using separate threads (or some kind of simulated asynchronicity) the 3 persons will need to wait on each other and using notifications doesn't really make sense.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top