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

问题描述

我有一个应用程序,它要求用户后台定位以触发某些事件和通知,类似于life360;如果用户终止了该应用,则后台位置更新仍应发生。

我的清单:

<key>uibackgroundmodes</key>
    <array>
        <string>fetch</string>
        <string>location</string>
        <string>processing</string>
        <string>remote-notification</string>
    </array>

在收到“始终”位置许可后,我已经像这样配置了CLLocationManager:

locationManager = CLLocationManager()
locationManager.delegate  = self
locationManager.allowsBackgroundLocationUpdates = true
locationManager.pausesLocationUpdatesAutomatically = false
locationManager.distanceFilter = kCLdistanceFilterNone  //meters
locationManager.desiredAccuracy = kCLLocationAccuracyBest

locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startMonitoringSignificantLocationChanges()
locationManager.startMonitoringVisits()

并且我已经设置了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启用了后台应用刷新功能,并且“始终”具有位置权限。我看到这个过程很繁琐而且非常耗时。

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...