如何测试iOS的后台位置更新?

如何测试iOS的后台位置更新?,ios,swift,cllocationmanager,cllocation,Ios,Swift,Cllocationmanager,Cllocation,我有一个应用程序,需要用户在后台的位置来触发某些事件和通知,类似于life360;如果用户终止应用程序,则仍应进行后台位置更新 我的朋友: <key>UIBackgroundModes</key> <array> <string>fetch</string> <string>location</string> <string>processing

我有一个应用程序,需要用户在后台的位置来触发某些事件和通知,类似于life360;如果用户终止应用程序,则仍应进行后台位置更新

我的朋友:

<key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>location</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>
我已经像这样设置了willFinishLaunching功能,以测试我的应用程序是否在位置更改时被调用:

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    if launchOptions?[UIApplication.LaunchOptionsKey.location] != nil {
        // App launched from the background due to location change
        UserDefaults.standard.set("Background Update Received", forKey: "locationUpdate")  
    }
    

    return true
    
}
在过去的几个小时里,我一直在我的城市里开车,我的应用程序试图触发位置更新,但从未发生过。我的iPhone具有后台应用程序刷新功能和“始终”位置权限。我已经看到这个过程是乏味和非常耗时的


我错过什么了吗?有没有比整天开车浪费汽油更好的测试方法?

你试过在模拟器中手动改变位置吗?@LudovicoVerniani是的,仍然没有收到更新。我不认为在模拟器中更改位置会触发后台位置更新。如果您已终止应用程序(从应用程序切换器刷起),则您将不会收到位置更新;您的应用程序已被用户终止。您可以尝试激活重要的位置更新,我相信这将重新启动您的app@Paulw11如果你仔细看,这正是我所做的。@Paulw11我只是设置了一个用户默认值来检查应用程序是否在一开始就被调用了,而事实并非如此。当然,即使在应用程序终止后也可以调用它,我只是无法让它工作。有什么想法吗?你试过在模拟器中手动更改位置吗?@LudovicoVerniani有,仍然没有收到更新。我不认为在模拟器中更改位置会触发后台位置更新。如果您已终止应用程序(从应用程序切换器刷起),则您将不会收到位置更新;您的应用程序已被用户终止。您可以尝试激活重要的位置更新,我相信这将重新启动您的app@Paulw11如果你仔细看,这正是我所做的。@Paulw11我只是设置了一个用户默认值来检查应用程序是否在一开始就被调用了,而事实并非如此。当然,即使在应用程序终止后也可以调用它,我只是无法让它工作。有什么想法吗?
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
    if launchOptions?[UIApplication.LaunchOptionsKey.location] != nil {
        // App launched from the background due to location change
        UserDefaults.standard.set("Background Update Received", forKey: "locationUpdate")  
    }
    

    return true
    
}