NSNotificationCenter: perform selector on main thread upon receipt of notification

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

  1. moonman239 macrumors 68000

    Mar 27, 2009
    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:

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

    Jul 23, 2008

Share This Page