2

I am trying to wait to retrieve data from my firebase database and store it in a dictionary. I am trying to use a semaphore to do so, but I am getting a NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9806) error which I tried to fix by changing my info.plist. But I had no luck with it. Is this not the way to go?

import UIKit
import Firebase

var done = false
class ListViewController: UIViewController, UICollectionViewDelegate {

let rootref = FIRDatabase.database().reference()
var item_dict = Dictionary<String,[String]>()
var item_img_dict = Dictionary<String,[String]>()
let semaphore = DispatchSemaphore(value: 0)
let queue = DispatchQueue.global()

override func viewDidLoad() {
    super.viewDidLoad()
    self.title = "hello!"
    print("before calling function==========================")
    print("go in to request")
    DispatchQueue.global(qos: .userInitiated).async{
        self.rootref.child("items").observeSingleEvent(of: .value, with: { (snapshot) in
            print("DOING SOMETHING IN FUNCTION !!!!")
            for(type_2_container,item_list) in snapshot.value! as! Dictionary<String, AnyObject>{
                for(uid_container, item_detail_container) in item_list as! Dictionary<String, AnyObject>{
                    for(uid, item_detail) in item_detail_container as! Dictionary<String, AnyObject>{
                        let item_detail_dict = item_detail as? Dictionary<String,String>
                        if self.item_dict.index(forKey: uid as! String) != nil{
                            self.item_dict[uid]?.append(item_detail_dict!["item_name"]!)
                            self.item_img_dict[uid]?.append(item_detail_dict!["item_image"]!)
                        }else{
                            self.item_dict[uid] = [item_detail_dict!["item_name"]!]
                            self.item_img_dict[uid] = [item_detail_dict!["item_image"]!]
                        }
                    }
                }
            }
            self.semaphore.signal()
        })
    }
    self.semaphore.wait()
    print(self.item_dict)
    print(self.item_img_dict)
}
David kim
  • 21
  • 3
  • Using `self.semaphore.wait()` in viewDidLoad is going to block the main thread, which is a really bad idea. Why aren't you just using the completion closure on the firebase call? – Michael Nov 16 '16 at 04:53
  • I'm really new to all this. Could you explain how to apply that to my code – David kim Nov 16 '16 at 06:03

1 Answers1

0

Thanks for ask question.

Already faced same issue.

You have just need to download new GoogleService-Info.plist file, Then replace with Existing file in the project.

It will solved your problem.

If above solution is not working for you then try given below solution.

Solution:2

1 ) Remove pod file from project (How to remove pod file)

2 ) Remove Old GoogleService-Info file from project.

3 ) Download GoogleService-Info and add into project.

4 ) Add pods file Again.

Then do test.

Community
  • 1
  • 1
Hitesh Surani
  • 12,733
  • 6
  • 54
  • 65