【问题标题】:Location service running background after 10 min app was closed应用程序关闭 10 分钟后定位服务运行后台
【发布时间】:2013-02-18 12:41:14
【问题描述】:

我在定位服务中的应用程序正在运行后台进程,但 10 分钟后应用程序被关闭。我正在使用以下步骤

1)在 .plist 文件中手动添加密钥

<key>Required background modes</key>
<array>
        <string>App registers for location updates</string>
</array>

2)代码是

 self.locationManager = [[CLLocationManager alloc] init];
[locationManager startUpdatingLocation];
locationManager.delegate = self;
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation    *)newLocation fromLocation:(CLLocation *)oldLocation {

   NSString *latVal = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.latitude];
    NSString *lonVal = [[NSString alloc] initWithFormat:@"%f", newLocation.coordinate.longitude];

}

我需要在后台频繁更新而没有关闭应用程序,请帮助我。

【问题讨论】:

    标签: iphone objective-c location cllocationmanager


    【解决方案1】:

    在您的didFinishLaunchingWithOptions我们这里。

    self.locationManager = [[CLLocationManager alloc] init];
    [locationManager startMonitoringSignificantLocationChanges];
    locationManager.delegate = self;
    

    这将确保即使您的应用程序已被终止,它也会被调用。

    【讨论】:

    • 感谢您的回复,我已实施后台服务,请参阅此链接-developer.blueearth.net/2011/12/02/…。但在 10 分钟的应用程序被杀死后它无法正常工作,请帮助我
    • 后台定位服务中是否有第三方API?
    • 位置变化时会再次触发。尝试模拟位置变化,看看它是否适合您。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多