Ios 应用程序发送到后台后位置停止更新
好吧,这是一个艰难的(无论如何对我来说)。。。我的应用程序有一个按钮,可以检查用户是否离公司很近。按下按钮时执行以下操作,几乎可以完美地工作:Ios 应用程序发送到后台后位置停止更新,ios,objective-c,cllocationmanager,Ios,Objective C,Cllocationmanager,好吧,这是一个艰难的(无论如何对我来说)。。。我的应用程序有一个按钮,可以检查用户是否离公司很近。按下按钮时执行以下操作,几乎可以完美地工作: 获取用户的纬度和经度坐标 将用户的纬度和经度坐标传递给PHP脚本 PHP脚本比较用户和企业之间的距离。如果用户在100英尺以内,脚本返回1;如果用户不在100英尺以内,脚本返回0 最后,该应用程序会显示一条警报,指出用户距离不到100英尺,或超过100英尺 就像我提到的,这几乎可以完美地工作。当我接近大楼时,我可以不断地点击按钮走向一家企业,当我足够
- 获取用户的纬度和经度坐标
- 将用户的纬度和经度坐标传递给PHP脚本
- PHP脚本比较用户和企业之间的距离。如果用户在100英尺以内,脚本返回1;如果用户不在100英尺以内,脚本返回0
- 最后,该应用程序会显示一条警报,指出用户距离不到100英尺,或超过100英尺
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appReturnsActive) name:UIApplicationDidBecomeActiveNotification
object:nil];
- (void)appReturnsActive{
locationManagerProfile.delegate = self;
locationManagerProfile.desiredAccuracy = kCLLocationAccuracyBest;
[locationManagerProfile startUpdatingLocation];
[locationManager startUpdatingLocation];
}
在评价活动方法中:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appReturnsActive) name:UIApplicationDidBecomeActiveNotification
object:nil];
- (void)appReturnsActive{
locationManagerProfile.delegate = self;
locationManagerProfile.desiredAccuracy = kCLLocationAccuracyBest;
[locationManagerProfile startUpdatingLocation];
[locationManager startUpdatingLocation];
}
为了节省电池,当应用程序转到后台时,位置更新将停止。您可以向info.plist添加值以保持应用程序的更新。但是你应该仔细考虑电池的使用。谢谢,让我说当我把它带回到前台时,我希望它马上开始更新。我已经更新了我的问题,以显示appDidWaken可能是什么样子……更新位置需要时间。如果你的应用在后台时没有其他应用或系统更新了位置信息,你无法立即获取当前位置。