2

In UIViewController I register for UIApplicationWillEnterForegroundNotification notification.

-(void)viewDidAppear:(BOOL)animated {
    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(btnContinuePressed:) 
                                                 name:UIApplicationWillEnterForegroundNotification 
                                               object:nil];
}

I want to execute btnContinuePressed: only if the application was resumed in a normal way - clicking the icon or opening via multitasking menu.

Method btnContinuePressed: should not be executed when the application was opened using URL scheme. Opening via URL scheme is handled in AppDelegate using custom notification:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"didOpenViaUrl" 
                                                        object:url];
    return YES;
}

Bottom line: notification UIApplicationWillEnterForegroundNotification should not be triggered if didOpenViaUrl was.

mathio
  • 568
  • 2
  • 11
  • Did you see this question / answer: http://stackoverflow.com/a/6037529/651651. seems promising. To me subscribing to WillEnterForeground inside a ViewController seems risky. I don't think you can be sure, that the VC is still in memory at that point. You might not get any notification at all in the worst case. – wrtsprt Aug 26 '15 at 09:45

1 Answers1

0

In simple word you can not make difference them but you can do a tricky way to achieve by creating a BOOL property in your appDelegate code which will tell you from where the application has been opened I think!

Retro
  • 3,985
  • 2
  • 17
  • 41