Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 在BGAppRefreshTask ios 13期间,URLSession失败_Json_Ios13_Background Task_Urlsession_Xcode12 - Fatal编程技术网

Json 在BGAppRefreshTask ios 13期间,URLSession失败

Json 在BGAppRefreshTask ios 13期间,URLSession失败,json,ios13,background-task,urlsession,xcode12,Json,Ios13,Background Task,Urlsession,Xcode12,我面临一个问题,在BGAppRefresh调用期间无法调用URLSession请求 我已经启用了后台提取功能,并在info.plist中添加了必要的键 后台获取被完美地调用,但是,当它使用completionHandler到达URLSession时失败 以下是AppDelegate代码: func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicatio

我面临一个问题,在BGAppRefresh调用期间无法调用URLSession请求

我已经启用了后台提取功能,并在info.plist中添加了必要的键

后台获取被完美地调用,但是,当它使用completionHandler到达URLSession时失败

以下是AppDelegate代码:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let register = BGTaskScheduler.shared.register(forTaskWithIdentifier: "ist.notification", using: nil) { task in
            self.handleDailyNotifications(task: task as! BGAppRefreshTask)
        }
}

func scheduleDailyNotificationRandomQASelection() {
        let request = BGAppRefreshTaskRequest(identifier: "ist.notification")
        request.earliestBeginDate = Date(timeIntervalSinceNow: 1*60)
        do {
               try BGTaskScheduler.shared.submit(request)
        } catch {
               print("Could not schedule Daily Notification's DB Fetcher Method: \(error)")
        }
}

@available(iOS 13.0, *)
private func handleDailyNotifications(task: BGAppRefreshTask) {
        let queue = OperationQueue()
        queue.maxConcurrentOperationCount = 1
        queue.addOperation {
            self.setNotifications()
        }
        task.expirationHandler = {
            queue.cancelAllOperations()
        }
        let lastOperation = queue.operations.last
        lastOperation?.completionBlock = {
            task.setTaskCompleted(success: !(lastOperation?.isCancelled ?? false))
        }
        scheduleDailyNotificationRandomQASelection()
}

func setNotifications() {
       let TimesURL = "xxx.com"
       if let url = URL(string: TimesURL!) {
            let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
            guard error == nil else {
                    print(error!)
                    return
             }
             if let data = data {
                   do {
                             //Json Parsing method//
                   }catch let error {
                              print("TimesURL Error:"+error.localizedDescription)
                   }
              }
        }
   }
   task.resume()
}
方法被卡住了

let task = URLSession.shared.dataTask(with: url) { (data, response, error) in
好心协助

非常感谢