Reputation: 497
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
return true
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let configuration = URLSessionConfiguration.background(withIdentifier: "smat.Tracker")
switch UIApplication.shared.applicationState {
case .active:
print("App is active.")
case .background:
print("App is in background.")
print("Background time remaining = \(UIApplication.shared.backgroundTimeRemaining) seconds")
case .inactive:
break
}
print(UIApplication.shared.applicationState.rawValue)
print(configuration.allowsCellularAccess)
print(configuration.timeoutIntervalForResource)
let headers: HTTPHeaders = [
"accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"referer": "https://frys.com/",
"host":"frys.com",
"upgrade-insecure-requests": "1",
"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"
]
configuration.httpAdditionalHeaders = headers
let base_url: String = "https://frys.com/search?search_type=regular&sqxts=1&cat=&query_string=" + "vivomove" + "&nearbyStoreName=false"
let sessionManager = Alamofire.SessionManager(configuration: configuration)
print("came here")
if(Trackers.urls.count > 0 ){
print(Trackers.urls.count)
}
Alamofire.request(base_url , headers: headers).responseString { response in
//print(response.result.value)
do {
print("response12 ")
guard let doc = try! response.result.value else{
completionHandler(.noData)
throw NSError(domain: "ERROR", code: 42, userInfo: ["BKGROUND":"err"])
}
completionHandler(.newData)
//self.endBackgroundTask()
}
catch {
print("error")
}
}
}
I have the above code in AppDelegate.swift. I read in several documents / tutorials that the minimum time required to finish a background task is 30 seconds or more. Why do I always get the above to be less than 2 seconds?
sample output below from console:
App is in background. Background time remaining = 1.79769313486232e+308 seconds 0.0 1.79769313486232e+308 UIApplicationState
Upvotes: 0
Views: 976
Reputation: 1033
It means you're running it under the XCode debugger.
While using a debugger, you receive bacgroundRemainginTime = 1.79769313486232e+308
, which is a huge number (1.79 * 10 ^ 308). It's the largest positive representable number in double-precision floating point format.
Upvotes: 1