gpt4 book ai didi

ios - swift 警告 : Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called

转载 作者:搜寻专家 更新时间:2023-10-31 22:54:44 27 4
gpt4 key购买 nike

我在下面的模拟器中调用这个函数来模拟后台获取。

然后我在日志中收到这个警告:

Swift Warning: Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called.

我看到其他 Stack Iverflow 回答说我只需要添加 completionhandler()。我试过了,它说我需要添加一个参数,这就是我迷路的地方。

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler:@escaping (UIBackgroundFetchResult) -> Void) {
let db = Firestore.firestore()
guard let uid = Auth.auth().currentUser?.uid else { return }

//check if user online
let docRef = db.collection("Users").document(uid)
docRef.getDocument { (document, error) in
if let document = document {
if document.exists {
guard let dictionary = document.data() else { return }
guard let onlineOfflineStatus = dictionary["Online Offline Status"] as? String else { return }

// if online create value to set offline an alert
if onlineOfflineStatus == "Online" {
print("user is Online and inactive, will set value to trigger notification asking if they would like to go offline")
db.collection("sendGoOffline").document(uid).setData(["OfflineAlert" : 1200], completion: { (error) in
if let error = error {
print("there was an error", error)
}
})
}
}
}

if let error = error {
print("failed to fetch user", error)
}
}
}

最佳答案

警告是告诉你添加这个方法:

completionHandler(argument)

参数是以下之一:

UIBackgroundFetchResult.noData
UIBackgroundFetchResult.newData
UIBackgroundFetchResult.failed

目的是告诉系统你已经完成了。

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler:@escaping (UIBackgroundFetchResult) -> Void) {

// do backgound data fetch

// process it

// finished
completionHandler(UIBackgroundFetchResult.newData)
}

在这里阅读更多:

远程通知相关文章

关于ios - swift 警告 : Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50901335/

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