【问题标题】:Where to put Firebase Performance trace在哪里放置 Firebase 性能跟踪
【发布时间】:2018-02-13 18:56:48
【问题描述】:

我正在尝试确定放置 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)
    }
  }
 }
}

最初我想将跟踪放在 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 Performance 目前不支持扩展

【问题讨论】:

    标签: swift firebase firebase-performance


    【解决方案1】:

    您是否在应用扩展的上下文中使用 Firebase 性能(例如手表、键盘、今日等)?该消息由 FirebasePerformance.h 文件中的这一行触发:

    NS_EXTENSION_UNAVAILABLE("FirebasePerformance 目前不支持应用扩展。")

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

    【讨论】:

    • 我确实有一个今天的扩展,但我 90% 确定该扩展没有使用特定方法(不是在计算机上)
    • 您能否仔细检查构建过程中的哪个阶段出现错误消息?您的 Today 扩展目标可能依赖于 Firebase Performance .h 文件,从而触发了该消息。
    猜你喜欢
    • 2019-08-26
    • 1970-01-01
    • 2014-10-06
    • 1970-01-01
    • 1970-01-01
    • 2013-03-26
    • 2016-10-01
    • 2013-05-24
    • 1970-01-01
    相关资源
    最近更新 更多