Firebase性能跟踪的位置

时间:2018-02-13 18:56:49

标签: swift firebase firebase-performance

我正在尝试确定放置firebase性能跟踪的最佳位置。我想看看我的应用程序提取数据需要多长时间。

在我的VC中,我有以下

  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)
    }
  }
 }
}

最初我想把跟踪放在我的单件类FirebaseUtility上,其中getCards方法是。

  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 Performance目前不支持扩展程序

1 个答案:

答案 0 :(得分:1)

您是否在应用扩展程序中使用Firebase Performance(例如,手表,键盘,今天等)?该消息由FirebasePerformance.h文件中的此行触发:

NS_EXTENSION_UNAVAILABLE(“FirebasePerformance目前不支持应用扩展程序。”)

Firebase Performance目前仅支持iOS上的普通应用程序。

相关问题