Check for launching from UILocalNotification in Swift

后端 未结 2 1719
有刺的猬
有刺的猬 2021-02-06 12:34

This is a follow-up question to How to check launchOptions in Swift? - I got my app to launch successfully without crashing, but I can\'t seem to correctly detect when the app i

相关标签:
2条回答
  • 2021-02-06 12:44

    If your App is running in background, the "application didFinishLaunching" method will not be called. It has already been launched.

    In this case you should do your job in the "application didReceiveLocalNotification" method.

    func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!) {
            // do your jobs here
    }
    
    0 讨论(0)
  • 2021-02-06 13:03

    LaunchOptions will be nil if you launch the application directly. The code will be running if you launch the application through the notifications rather than launch the application directly.

    If you launch the application directly, then you need some other ways to solve this. Like use the time of the LocalNotification and the current time, and decide which view to show.

    0 讨论(0)
提交回复
热议问题