gpt4 book ai didi

Swift:忽略启动新后台任务的请求,因为 RunningBoard 已经启动了到期计时器

转载 作者:行者123 更新时间:2023-12-04 12:34:27 25 4
gpt4 key购买 nike

我有一系列由静默推送通知触发的任务。收到推送通知后,它会在后台唤醒 iOS 并执行以下任务:

  • 打开一个包含 WKWebview 的 WebViewController
  • 进入网页,点击一些由 javascript 注入(inject)自动生成的按钮
  • 完成后,关闭 WebViewController

  • 我已经添加了选定的 BackgroundTasks 处理程序来管理它,方法如下 tutorial但控制台充斥着以下警告。
    [ProcessSuspension] 0x280486080 - WKProcessAssertionBackgroundTaskManager: Ignored request to start a new background task because RunningBoard has already started the expiration timer
    请注意,需要完成的任务仍然正确执行。
    class WebViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHandler {

    lazy var webView: WKWebView = {
    let v = WKWebView()
    v.translatesAutoresizingMaskIntoConstraints = false
    v.navigationDelegate = self
    return v
    }()

    var backgroundTask: UIBackgroundTaskIdentifier = .invalid

    //Remove BG task when not needed
    deinit {
    NotificationCenter.default.removeObserver(self)
    endBackgroundTask()
    }

    override func viewDidLoad() {
    super.viewDidLoad()

    //Register notification for background task
    NotificationCenter.default.addObserver(self,
    selector: #selector(reinstateBackgroundTask),
    name: UIApplication.didBecomeActiveNotification,
    object: nil)
    registerBackgroundTask()


    //Load webview with URL
    if let url = url {
    let request = URLRequest(url: url)
    webView.load(request)
    }
    }

    //MARK:- Handle BG Tasks

    func registerBackgroundTask() {
    backgroundTask = UIApplication.shared.beginBackgroundTask { [weak self] in
    self?.endBackgroundTask()
    }
    }

    func endBackgroundTask() {
    Log("Background task ended.")
    UIApplication.shared.endBackgroundTask(backgroundTask)
    backgroundTask = .invalid
    }

    @objc func reinstateBackgroundTask() {
    if backgroundTask == .invalid {
    registerBackgroundTask()
    }
    }

    func endBackgroundTaskIfNotInvalid() {
    if backgroundTask != .invalid {
    self.endBackgroundTask()
    }
    }

    //This is the final task that needs to be done
    fileprivate func updateScheduler(visitedPlace: VisitedPlace) {
    if navigator == .scheduler {

    if let jobId = jobId {
    let data = [
    "status": "scheduled",
    "completedOn": Date()
    ] as [String : Any]

    ///Do some work here...

    //Dismiss controller after completing
    self.dismiss(animated: true) {
    self.endBackgroundTaskIfNotInvalid()
    }
    }
    } else {
    self.endBackgroundTaskIfNotInvalid()
    }
    }
    }
    是什么触发了所有这些警告,我该如何使其静音?

    最佳答案

    我有同样的控制台泛滥。对我来说,结果是 adMob 导致的。

    关于Swift:忽略启动新后台任务的请求,因为 RunningBoard 已经启动了到期计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66210060/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com