UIApplicationWillEnterForegroundNotification vs application:openURL:sourceApplication:annotation:

StackOverflow https://stackoverflow.com/questions/21425466

  •  04-10-2022
  •  | 
  •  

سؤال

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.

هل كانت مفيدة؟

المحلول

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!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top