gpt4 book ai didi

ios - 15 分钟后,后台位置更新在 iOS 中不起作用?

转载 作者:行者123 更新时间:2023-11-29 00:36:42 24 4
gpt4 key购买 nike

我已经在 iOS 中根据计时器(比如每 1 分钟)实现了后台位置更新。它工作正常并获取位置(lat 和 Long 值)但在 15 之后它断开连接。我无法再触发它了。谁能帮帮我。

这是我的代码..

- (void)applicationDidEnterBackground:(UIApplication *)application {

[[GlobalClass sharedGlobals].locationManager stopMonitoringSignificantLocationChanges];

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8) {
[[GlobalClass sharedGlobals].locationManager requestAlwaysAuthorization];
}
[[GlobalClass sharedGlobals].locationManager startMonitoringSignificantLocationChanges];

int timeInterval = 60; // (i.e., 1 mins )

if (!setTimer) {
setTimer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target: self
selector: @selector(toMakeServerCall) userInfo: nil repeats: YES];
}
}

#pragma mark - Send Current lat & long to the server

- (void)toMakeServerCall {

NSString *latitude = [NSString stringWithFormat:@"%f",[[GlobalClass sharedGlobals] currentLocationObject].coordinate.latitude];
NSString *longitude = [NSString stringWithFormat:@"%f",[[GlobalClass sharedGlobals] currentLocationObject].coordinate.longitude];

NSLog(@"Current Lat is :%@ \n Current Long is :%@ ",latitude,longitude);

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http:www.google.com/myLatitude is: %@ and My Longitude is: %@",latitude,longitude]];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

}

提前致谢。

最佳答案

当您使用“重大更改”服务(或坦率地说任何位置服务)时,您不使用计时器。当位置发生变化时,操作系统会调用,而不是相反。

关于您的计时器,当应用程序暂停时,计时器将不再运行。所以,不要使用计时器。但通过重大变更服务,当设备检测到它已移动了很远的距离时,您的应用程序将被唤醒并收到通知。作为Location and Maps Programming Guide: Starting the Significant-Change Location Service说:

If you leave the significant-change location service running and your iOS app is subsequently suspended or terminated, the service automatically wakes up your app when new location data arrives. At wake-up time, the app is put into the background and you are given a small amount of time (around 10 seconds) to manually restart location services and process the location data. (You must manually restart location services in the background before any pending location updates can be delivered, as described in Knowing When to Start Location Services.) Because your app is in the background, it must do minimal work and avoid any tasks (such as querying the network) that might prevent it from returning before the allocated time expires. If it does not, your app will be terminated. If an iOS app needs more time to process the location data, it can request more background execution time using the beginBackgroundTaskWithName:expirationHandler: method of the UIApplication class.

关于ios - 15 分钟后,后台位置更新在 iOS 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40429171/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com