2

I have investigated siginificant location. I would like to get location information when not running app. https://developer.apple.com/documentation/corelocation/getting_the_user_s_location/using_the_significant-change_location_service

The following code is an trigger for getting location information.

func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        if launchOptions?[.location] != nil {
            locationManager.startMonitoringSignificantLocationChanges()
        }
        return true
    }

But I encountered a strange behavior.
When an app launch by significant location event.

AppDelegate only: launchOptions?[.location] isn’t nil
AppDelegate + SceneDelegate: launchOptions?[.location] is always nil

I couldn’t get similar value from SceneDelegate method.

SceneDelegate screenshot

If I want to use launchOptions related to location, is it better to use AppDelegate only?

funzin
  • 21
  • 3
  • In the screenshot you posted you need to step through one more line of code to see if `notificationResponse` is nil or not. – HangarRash May 19 '23 at 14:30

1 Answers1

-1

When you work with the scene delegate you should use scene(:,willConnectTo session:,options:) function instead

 func scene(_ scene: UIScene,
               willConnectTo session: UISceneSession,
               options connectionOptions: UIScene.ConnectionOptions) {
// handle universal links
        if let userActivity = connectionOptions.userActivities.first {
            self.scene(scene, continue: userActivity)
        } else {
// handle other urls (f.e. your custom schemes)
            self.scene(scene, openURLContexts: connectionOptions.urlContexts)
        }
    }
Oleg Kovtun
  • 362
  • 1
  • 3
  • Note that the OP has already tried using the scene delegate (see the screenshot posted in the question). The question is asking how to determine if the scene is being launched due to a location update. – HangarRash May 19 '23 at 14:46
  • In the attached screenshot breakpoint stands on the wrong line. – Oleg Kovtun Aug 04 '23 at 09:38
  • Yes, I made a comment about that below the question. My comment to your answer is that your answer is telling the OP to use the scene delegate but the OP has already try the scene delegate. And your code in the scene delegate has nothing to do with a location update. Given those two things, your answer doesn't solve the issue at all. – HangarRash Aug 04 '23 at 16:30