簡體   English   中英

ios應用后台運行

[英]ios app background run

像“blitzer.de”這樣的應用程序如何在此處輸入圖像描述可以在后台連續運行? 在此處輸入圖像描述我正在嘗試創建一個這樣的應用程序,並讓它在后台運行大約 2 小時,同時使用 gps 數據。 我的研究告訴我,蘋果對后台運行非常嚴格,會在 3 分鍾內取消該過程。 此外,提取將在 6 分鍾內結束。 任何幫助將不勝感激。

@約翰內斯

1) 任何應用程序都可以在后台運行不超過10 分鍾 但這里是Background Enabled App 的一個例外。 所以你必須從

功能 > 后台模式在此處輸入圖片說明

2)現在您必須請求位置跟蹤的許可——始終在應用程序的 info.plist 中

NSLocationAlwaysUsageDescription --- 我需要位置

NSLocationWhenInUseUsageDescription --- 我需要位置

隱私 - 位置使用說明 --- 我需要位置

在此處輸入圖片說明

3)現在最重要。 編碼

  self.locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
    _locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
    [self.locationManager requestAlwaysAuthorization];
    self.locationManager.delegate = self;
    if([self.locationManager respondsToSelector:@selector(allowsBackgroundLocationUpdates)]) {
        [self.locationManager setAllowsBackgroundLocationUpdates: YES];
    }
    self.locationManager.distanceFilter = 50 ; // 
    self.locationManager.activityType=CLActivityTypeAutomotiveNavigation;
    [self.locationManager startUpdatingLocation];
    [self.locationManager setPausesLocationUpdatesAutomatically:NO];

4)。 setPausesLocationUpdatesAutomatically:NO 將允許您的應用程序連續運行。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM