我试图确定放置firebase性能跟踪的最佳位置。我想看看我的应用程序需要多长时间来提取数据。
在我的风险投资中,我有以下几点

  func pullAllUsersCards() {
// 1 Start Here?
FirebaseUtility.shared.getCards { (cards, errMessage) in
  if let theCards = cards {
    if theCards.count < 1 {
      if let addVC = self.storyboard?.instantiateViewController(withIdentifier: StoryboardKeys.addCardViewControllerStoryboardID) as? AddCardViewController {
        let addNavigation = UINavigationController(rootViewController: addVC)
        if UIDevice.current.userInterfaceIdiom == .pad {
          self.splitViewController?.present(addNavigation, animated: true, completion: nil)
        } else {
          self.present(addNavigation, animated: true, completion: nil)
        }
      }
    } else {
      // 2 Start Here?
      MBProgressHUD.showAdded(to: self.view, animated: true)
      self.cardArray = theCards
      self.tableView.reloadData()
      MBProgressHUD.hide(for: self.view, animated: true)
    }
  }
 }
}

最初,我想在getCards方法所在的单例类FirebaseUtility上进行跟踪。
  func getCards(completion: @escaping (_ cards: [Card]?, _ errorMessage: String?) -> Void) {
//    let testTrace = Performance.startTrace(name: "Test")
guard let userID = user?.uid else {
  let error = "Unknown error occured! User is not logged in."
  completion(nil, error)
  return
}

let userCardRef = ref.child(FirebaseKeys.newCards).child(userID)
userCardRef.observe(.value, with: { (snapshot) in // changed from Single Event
  let enumerator = snapshot.children
  var cards = [Card]()

  while let cardSnapshot = enumerator.nextObject() as? DataSnapshot {
    if let cardDict = cardSnapshot.value as? [String : Any] {
      let card = Card(id: cardSnapshot.key, cardDict: cardDict)
      cards.append(card)
    }
  }
  completion(cards, nil)
})
//    testTrace?.stop()
}

但是,当我尝试在那里使用它时,我得到一个错误,说Firebase性能目前不支持扩展

最佳答案

您是否在应用程序扩展的上下文中使用Firebase性能(例如手表、键盘、今日等)?该消息由FirebasePerformance.h文件中的此行触发:
NS_EXTENSION_UNAVAILABLE(“FirebasePerformance目前不支持应用程序扩展。”)
Firebase性能目前仅支持iOS上的普通应用程序。

08-17 20:30