菜鸟教程小白 发表于 2022-12-11 18:32:35

ios - 如何在后台为 Firebase 实时数据库设置值?


                                            <p><p>我这样在后台调用 setValue():</p>

<pre><code>func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: , fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {

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

<p>但从未调用完成 block 。后台不能上传数据吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>Apple 允许在后台调用少数功能</p>

<ol>
<li>麦克风</li>
<li>位置更新</li>
<li>蓝牙配件</li>
<li>网络电话</li>
</ol></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在后台为 Firebase 实时数据库设置值?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41566373/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41566373/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在后台为 Firebase 实时数据库设置值?