title: iOS local notification: I would like to execute a function upon reentering the app via local notification
body: <p>I'm working with XCode 4.6, and am trying to build a local notification feature on iOS that will execute a function upon reentering the app.Basically I would like to change the text in some of the labels and add some sound upon reentering the app. I thought I was on the right track, but only some parts of my code work when reentering the app via local notification. </p>
  
  <p>First I added this function to my AppDelegate: </p>
  
  <pre><code>-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
      NSLog(@"test1");   //this traces successfully 
      myAppViewController * controller = [myAppViewController alloc];
      [controller doSomething];  //calling a function in my myAppViewController.m
  }
  </code></pre>
  
  <p>I thought I had figured it out, but now only the NSLog works in my function in myAppViewController.m: </p>
  
  <pre><code>-(void)doSomething{
      NSLog(@"do something"); //traces successfully 
      self.notificationTime.text=@"something else"; //nothing happens here, it works in other functions but not here
      [self doSomethingElse]; //calling another function from this function for further testing 
  }
  </code></pre>
  
  <p>The next function is called.... </p>
  
  <pre><code>-(void)doSomethingElse{
      NSLog(@"do something else"); //this works
      //this whole thing doesn't work -- no sound -- 
      NSURL* url = [[NSBundle mainBundle] URLForResource:@"cash" withExtension:@"mp3"];
      NSAssert(url, @"URL is valid.");
      self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
      [self.player prepareToPlay];
      [self.player play];
      //this doesn't work again
      self.notificationTime.text=@"something else";
  }
  </code></pre>
  
  <p>I was hoping to get some general advice here and it would be much appreciated. If anyone knows a complete different way of solving the problem, that would be great as well!</p>