Xcode6.3.2,模拟器版本系统8.3,真机系统版本6.1.3
测试说明:过程中发现同时使用requestAlwaysAuthorization和requestWhenInUseAuthorization请求权限的情况下,app会优先执行顺序靠前的请求,而忽略掉后面的.例如同时使用:
[_manager requestWhenInUseAuthorization];
[_manager requestAlwaysAuthorization];
安装应用后弹出框为requestWhenInUseAuthorization的相关提示,进入系统"设置->隐私->位置"也仅为"使用期间".故测试代码均指测试了单一语句.
新建一个名为BackgroundLocation的测试工程,在TARGETS->Capabilities中找到BackgroundModes,点击开启后勾选下面的Location updates.之后的测试中将会测试开启和关闭这个选项的情况.
安装app,系统提示:
点击Allow,系统开始输入打印日志:
即时将程序最小化到后台后者锁屏,依然有打印输出.但是系统会有如下图提示,锁屏时导航栏也会变色:
安装app,系统提示:
点击允许,开始输入打印日志.将程序最小化到后台或者锁屏,依然有打印输出,但是系统界面一切正常,没有条件1中的提示.
系统提示框同条件1,但最小化和锁屏后不再有打印输出,说明进入后台后没有继续进行定位.
系统提示框同条件2,但最小化和锁屏后依然有打印输出,系统界面也都一切正常,没有条件1中的隐私提醒.
但通过对比条件2和条件4发现两者好像并没有什么区别,那BackgroundMode究竟有什么用呢?
Enabling this mode does not prevent the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver. Thus, this key effectively lets the app run in the background to process location updates whenever they occur.
大意为:开启UIBackgroundModes-location updates并不能阻止系统挂起你的app,但是它告诉系统应该在有新的地址位置更新时唤醒app,通过这种方式不论在什么时候你的app都能处理位置更新.
但是,然并卵,模拟器测试一直没有成功,等待真机测试中.
//Using the Standard Location Service in the Background
The system delivers location updates to background location apps when the app is in the foreground, is running in the background, or is suspended. In the case of a suspended app, the system wakes up the app, delivers the update to the location manager’s delegate, and then returns the app to the suspended state as soon as possible. While it is running in the background, your app should do as little work as possible to process the new location data.
Note: If your app is terminated either by a user or by the system, the system doesn’t automatically restart your app when new location updates arrive. A user must explicitly relaunch your app before the delivery of location updates resumes. The only way to have your app relaunched automatically is to use region monitoring or the significant-change location service.
注意:If your app is terminated either by a user or by the system, the system doesn’t automatically restart your app when new location updates arrive!!!
然并卵,模拟器依旧没有测试成功.求成功案例!!求成功案例!!求成功案例!!
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文地址:http://blog.csdn.net/qq329735967/article/details/47722949