2014年初,Apple已将iOS 7.0更新为7.1,以便即使应用程序在前台而非后台处于活动状态时也允许位置更新.我们怎么做?
我读过一些文章,比如Apple的iOS 7.1将修复地理定位错误.但是,即使应用程序被终止/终止/暂停,Apple也没有提供与此相关的任何通信,也没有提供有关如何获取位置更新的示例代码.
我已阅读iOS 7.1发行说明.我也找不到任何相关的东西.
那么,即使应用程序被暂停,我们如何实际获得iOS 7和8的位置更新?
我甚至在所有州都尝试获取位置更新,即使应用程序被终止/终止/暂停也是如此.我在xcode中启用了后台提取并实现了以下代码(使用了参考" 在所有状态app中捕获位置 ").但是,当我终止应用程序时,它会在AppDelegate类上给出一条红线.我不明白这里有什么问题.我已经使用" 获取iOS应用程序的位置,当它在后台甚至被杀 " 这个问题的解决方案,但它不适用于ios 9.请帮助我出或告诉我其他解决方案.
更新的代码 -
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
var window: UIWindow?
var locationManager: CLLocationManager?
var significatLocationManager : CLLocationManager?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
if(UIApplication.sharedApplication().backgroundRefreshStatus == UIBackgroundRefreshStatus.Available){
print("yessssss")
}else{
print("noooooo")
}
if let launchOpt = launchOptions{
if (launchOpt[UIApplicationLaunchOptionsLocationKey] != nil) {
self.significatLocationManager = CLLocationManager()
self.significatLocationManager?.delegate = self
self.significatLocationManager?.requestAlwaysAuthorization()
if #available(iOS 9.0, *) {
self.significatLocationManager!.allowsBackgroundLocationUpdates = true
}
self.significatLocationManager?.startMonitoringSignificantLocationChanges()
}else{
self.locationManager = CLLocationManager()
self.locationManager?.delegate = self
self.locationManager?.requestAlwaysAuthorization()
if #available(iOS …Run Code Online (Sandbox Code Playgroud) 我想让我的应用程序继续在后台运行位置服务.为此我用过:
-(void)applicationDidEnterBackground:(UIApplication *)application {
[locationManager stopUpdatingLocation];
[locationManager startUpdatingLocation];
//timer=[NSTimer scheduledTimerWithTimeInterval:300 target:self selector:@selector(UpdateLocation) userInfo:nil repeats:YES];
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用NSTimer它时不会打电话UpdateLocation.我尝试使用另一种方法调用它,但之后它也只调用一次.
我想在后台持续运行应用程序,在定期间隔后检测位置.
有没有办法安排每天在特定时间调用 Web 服务的函数?
根据我的研究,我将不得不使用本地通知或NSTimer在特定时间安排或调用该功能。但是,无论我的应用程序是在计划时间处于后台(并且不运行任何后台任务)还是在前台,我都需要它来工作。
有两种情况: 1. 我的应用程序在后台运行位置服务 2. 没有位置或后台服务正在运行,或者应用程序处于挂起状态(如果用户禁用了位置更新)
但是我必须每天在预定时间向我的服务器发送一些状态。