iOS后台提取在实际设备(iPad和iPhone)中不起作用
我已经使用Swift 5.0创建了一个iOS本机应用程序,如果应用程序在后台模式下运行,它可以使用iOS的iOS后台提取在实际设备(iPad和iPhone)中不起作用,ios,swift,xcode,Ios,Swift,Xcode,我已经使用Swift 5.0创建了一个iOS本机应用程序,如果应用程序在后台模式下运行,它可以使用iOS的后台提取功能从服务器内部提取数据。后台提取在模拟器中正常工作(在XCode中模拟后台提取)。但是,在真正的设备(ipadair和ios12.2)中,后台根本无法工作 我已经完成了以下步骤 在Xcode中的目标上启用了“功能”下的“后台模式”的Background fetch。 2.在AppDelegate.swift类中配置了最小后台fecth间隔和“performFetchWithCom
后台提取
功能从服务器内部提取数据。后台提取在模拟器中正常工作(在XCode中模拟后台提取)。但是,在真正的设备(ipadair和ios12.2)中,后台根本无法工作
我已经完成了以下步骤
Background fetch
。
AppDelegate.swift
类中配置了最小后台fecth间隔和“performFetchWithCompletionHandler”方法
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
UIApplication.shared.setMinimumBackgroundFetchInterval(TimeInterval(60*15))
return true
}
func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let url = URL(string: "http://192.168.225.24:80/product") {
URLSession.shared.dataTask(with: url, completionHandler: { (data, respone, error) in
guard let `data` = data else { completionHandler(.failed); return }
let result = String(data: data, encoding: .utf8)
print("performFetchWithCompletionHandler result: \(String(describing: result))")
completionHandler(.newData)
}).resume()
}
}
}
我通过XCode的Simulate Background Fetch
检查模拟器,然后HTTP请求到达服务器。此外,我还验证了真正的设备是否在应用程序的设置中启用了背景刷新功能
但在实际设备上,后台提取不起作用。原因是什么?请帮助我解决问题。是否调用了您的完成处理程序?设备控制台中是否有任何相关消息?未调用任何完成处理程序,控制台中没有消息。是否确定服务器始终可访问?它似乎是本地服务器。如果设备连接到移动网络怎么办?是的,服务托管在内部网中,服务在专用网络中始终可用。在进行模拟抓取时,服务调用到达服务器