NSNotificationCenter: perform selector on main thread upon receipt of notification

Discussion in 'iOS Programming' started by moonman239, Nov 15, 2014.

  1. moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I have the following code in my app right now. My app works, but what I really want is for playerItemDidFinishPlaying to be executed on the main thread. I guess I could just create a new method that will be called instead, and use the performSelectorOnMainThread method.

    So, instead of this:

    Code:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playerItemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    
    I'd have this:
    Code:
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(someMethod) name:AVPlayerItemDidPlayToEndTimeNotification object:nil];
    
    -(void)someMethod
    {
    [self performSelectorOnMainThread:@selector(playerItemDiDFinishPlaying)
    
     
  2. kage207 macrumors 6502a

    Joined:
    Jul 23, 2008
    #2

Share This Page