亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

背景位置服務不適用于IOS 7

背景位置服務不適用于IOS 7

iOS
繁星淼淼 2019-08-02 03:02:09
背景位置服務不適用于IOS 7我最近升級了我的iOS設備以使用iOS 7。我們正在開發的一個應用程序使用后臺定位服務來跟蹤設備位置,我們的所有測試人員都報告說,該應用程序似乎不再跟蹤iOS 7下的背景信息。我們已經證實,在設備上的設置中啟用了該應用程序的回退,而之前的構建在iOS 6下運行得非常完美。即使該設備被循環使用,該應用程序在位置更新后也會重新啟動。在iOS 7下,是否還需要做一些其他的工作呢?
查看完整描述

3 回答

?
鳳凰求蠱

TA貢獻1825條經驗 獲得超4個贊

這里是我用來從iOS 7設備上獲得連續定位的解決方案,不管它是在前臺還是在后臺。

您可以從Blog和GitHub找到完整的解決方案和解釋:-

  1. iOS 7和8的背景位置更新編程

  2. GitHub項目:iOS 7和8的背景位置更新編程

方法和解釋:-

  1. 我每1分鐘重新啟動一次位置管理器。DIDUpdateLocations

  2. 我允許位置管理器從設備中獲取10秒的位置,然后關閉它(以節省電池)。

以下部分法典:-

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{for(int i=0;i<locations.count;i++){
    CLLocation * newLocation = [locations objectAtIndex:i];
    CLLocationCoordinate2D theLocation = newLocation.coordinate;
    CLLocationAccuracy theAccuracy = newLocation.horizontalAccuracy;
    NSTimeInterval locationAge = -[newLocation.timestamp timeIntervalSinceNow];

    if (locationAge > 30.0)
        continue;

    //Select only valid location and also location with good accuracy
    if(newLocation!=nil&&theAccuracy>0
       &&theAccuracy<2000
       &&(!(theLocation.latitude==0.0&&theLocation.longitude==0.0))){
        self.myLastLocation = theLocation;
        self.myLastLocationAccuracy= theAccuracy;
        NSMutableDictionary * dict = [[NSMutableDictionary alloc]init];
        [dict setObject:[NSNumber numberWithFloat:theLocation.latitude] forKey:@"latitude"];
        [dict setObject:[NSNumber numberWithFloat:theLocation.longitude] forKey:@"longitude"];
        [dict setObject:[NSNumber numberWithFloat:theAccuracy] forKey:@"theAccuracy"];
        //Add the vallid location with good accuracy into an array
        //Every 1 minute, I will select the best location based on accuracy and send to server
        [self.shareModel.myLocationArray addObject:dict];
    }}//If the timer still valid, return it (Will not run the code below)if (self.shareModel.timer)
    return;self.shareModel.bgTask = [BackgroundTaskManager sharedBackgroundTaskManager];[self.shareModel.bgTask beginNewBackgroundTask];//Restart the locationMaanger after 1 minuteself.shareModel.timer = [NSTimer scheduledTimerWithTimeInterval:60 target:self
                                                       selector:@selector(restartLocationUpdates)
                                                       userInfo:nil
                                                        repeats:NO];//Will only stop the locationManager after 10 seconds, so that we can get some accurate locations//The location manager will only operate for 10 seconds to save batteryNSTimer * delay10Seconds;delay10Seconds = [NSTimer scheduledTimerWithTimeInterval:10 target:self
                                                selector:@selector(stopLocationDelayBy10Seconds)
                                                userInfo:nil
                                                 repeats:NO];
 }

我收到了一些請求,要求在一定時間間隔內向服務器發送位置時添加示例代碼。我添加了示例代碼,并結合了背景任務管理器的修復來解決后臺運行較長時間的故障。如果您有任何問題,歡迎您加入我們的討論:iOS 7的后臺位置更新編程與位置更新到服務器討論

如果您希望在應用程序被掛起時獲得位置更新,請參見:獲取iOS應用程序的位置更新,即使掛起




查看完整回答
反對 回復 2019-08-03
?
一只斗牛犬

TA貢獻1784條經驗 獲得超2個贊

我認為他們做了一個優化(可能使用運動傳感器),以檢測手機的“相對”靜止定位,他們停止位置更新。這只是猜測,但我目前的測試顯示:

  1. 開始位置更新;(測試精度為10米和100米,每次3次)
  2. 關閉設備屏幕,將應用程序放到后臺;
  3. 將設備靜止不動(例如在桌子上)30分鐘。

我記錄的數據顯示,地學更新在大約15米和30米之后停止。這樣,您所做的所有其他后臺處理也將終止。

我的設備是iPhone 5和iOS 7。

我95%肯定,iOS 6/6.1的情況并非如此。在那里獲得100米精度的地理更新,可以讓你在后臺連續運行。

如果每8分鐘重新啟動一次位置管理器,它應該會連續運行。

我還沒有在最新的測試,但這是我如何重新啟動它時,我寫了這篇文章。我希望這是有幫助的。

- (void)tryRestartLocationManager{
    NSTimeInterval now = [[NSDate date] timeIntervalSince1970];

    int seconds = round(floor(now - locationManagerStartTimestamp));

    if ( seconds > (60 * 8) ) {
        [locationManager stopUpdatingLocation];
        [locationManager startUpdatingLocation];
        locationManagerStartTimestamp = now;
    }}




查看完整回答
反對 回復 2019-08-03
  • 3 回答
  • 0 關注
  • 475 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號