OGeek|极客世界-中国程序员成长平台

标题: ios - 如何在后台为 Firebase 实时数据库设置值? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:32
标题: ios - 如何在后台为 Firebase 实时数据库设置值?

我这样在后台调用 setValue():

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    let semaphore: DispatchSemaphore = DispatchSemaphore(value: 0)
    let ref = FIRDatabase.database().reference().child("data")
    let data: NSDictionary = [
        "test" : "test"
    ]
    ref.setValue(data, withCompletionBlock:{
        (error, reference) in
        if error != nil {
            print(error!)
        } else {
            print("success")
            semaphore.signal()  
        }
    })
    _ = semaphore.wait(timeout: .distantFuture)
    completionHandler(.newData)
}

但从未调用完成 block 。后台不能上传数据吗?



Best Answer-推荐答案


Apple 允许在后台调用少数功能

  1. 麦克风
  2. 位置更新
  3. 蓝牙配件
  4. 网络电话

关于ios - 如何在后台为 Firebase 实时数据库设置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41566373/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4