菜鸟教程小白 发表于 2022-12-11 18:04:51

ios - 等待 firebase 请求加载以继续的问题


                                            <p><p>我正在等待从我的 firebase 数据库中检索数据并将其存储在字典中。
我正在尝试使用信号量来执行此操作,但出现 NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806) 错误
我试图通过更改我的 info.plist 来解决这个问题。但我没有运气。这不是要走的路吗?</p>

<pre><code>import UIKit
import Firebase

var done = false
class ListViewController: UIViewController, UICollectionViewDelegate {

let rootref = FIRDatabase.database().reference()
var item_dict = Dictionary&lt;String,&gt;()
var item_img_dict = Dictionary&lt;String,&gt;()
let semaphore = DispatchSemaphore(value: 0)
let queue = DispatchQueue.global()

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = &#34;hello!&#34;
    print(&#34;before calling function==========================&#34;)
    print(&#34;go in to request&#34;)
    DispatchQueue.global(qos: .userInitiated).async{
      self.rootref.child(&#34;items&#34;).observeSingleEvent(of: .value, with: { (snapshot) in
            print(&#34;DOING SOMETHING IN FUNCTION !!!!&#34;)
            for(type_2_container,item_list) in snapshot.value! as! Dictionary&lt;String, AnyObject&gt;{
                for(uid_container, item_detail_container) in item_list as! Dictionary&lt;String, AnyObject&gt;{
                  for(uid, item_detail) in item_detail_container as! Dictionary&lt;String, AnyObject&gt;{
                        let item_detail_dict = item_detail as? Dictionary&lt;String,String&gt;
                        if self.item_dict.index(forKey: uid as! String) != nil{
                            self.item_dict?.append(item_detail_dict![&#34;item_name&#34;]!)
                            self.item_img_dict?.append(item_detail_dict![&#34;item_image&#34;]!)
                        }else{
                            self.item_dict = !]
                            self.item_img_dict = !]
                        }
                  }
                }
            }
            self.semaphore.signal()
      })
    }
    self.semaphore.wait()
    print(self.item_dict)
    print(self.item_img_dict)
}
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>感谢提问。</p>

<p>已经面临同样的问题。</p>

<p>您只需下载新的<code>GoogleService-Info.plist</code>文件,然后替换为项目中的现有文件。</p>

<p>它会解决你的问题。</p>

<p>如果上述解决方案不适合您,请尝试以下解决方案。</p>

<p><strong>解决方案:2</strong></p>

<p>1 ) 从项目中移除 <code>pod</code> 文件 (<a href="https://stackoverflow.com/questions/16427421/how-to-remove-cocoapods-from-a-project" rel="noreferrer noopener nofollow">How to remove pod file</a>)</p>

<p>2 ) 从项目中删除旧的 <code>GoogleService-Info</code> 文件。</p>

<p>3 ) 下载 <code>GoogleService-Info</code> 并添加到项目中。</p>

<p>4 ) 再次添加 <code>pods</code> 文件。</p>

<p>然后进行测试。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 等待 firebase 请求加载以继续的问题,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40623533/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40623533/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 等待 firebase 请求加载以继续的问题