The UIApplicationDelegate protocol defines several methods that allow you to add code to several lifecycle events of your application.
Of particular interest to you will be the following:
application(_:willFinishLaunchingWithOptions:) - called just before the application application(_:willFinishLaunchingWithOptions:) , when the application was not already active in the backgroundapplication(_:didFinishLaunchingWithOptions:) - called immediately after the application has completed launch, when the application was not already active in the backgroundapplicationDidBecomeActive(_:) - called immediately after the application has become active, it is called when the user starts from scratch, opens from the background again, and also when the user returns with a temporary interruption (for example, a phone call)applicationWillEnterForeground(_:) - this is called just before the application comes to the foreground after it was in the background - it is immediately followed by a call to applicationDidBecomeActive(_:)
These life cycle events can cause the user to open the application through a notification or by clicking on the icon. As far as I know, there is no way to say for sure that the application was opened by clicking the icon. You may know (ish) that the application was not opened through a notification, since the corresponding methods "received a notification" will never work. But it still allows the user to use two (at least) methods of opening the application: clicking on the application icon or double-clicking the home button and clicking on the application to wake it from the background.
source share