Firebase IOS:警告“setScreenName:screenClass:必须在视图控制器出现后调用”

时间:2017-01-12 14:12:52

标签: ios firebase google-tag-manager

我想了解我从Firbase IOS获得的警告

<FIRAnalytics/WARNING> setScreenName:screenClass: must be called after a view controller has appeared

我的info.plist包含

FirebaseAutomaticScreenReportingEnabled = NO

我正在打电话

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    recordScreenView()    
}

func recordScreenView() {
    // title from the story board
    // These strings must be <= 36 characters long in order for setScreenName:screenClass: to succeed.
    guard let screenName = title else {
        return
    }
    let screenClass = classForCoder.description()

    // [START set_current_screen]
     GCITracking.sharedInstance.trackSetScreenName(screenName, screenClass: screenClass)
    // [END set_current_screen]
}

取自示例应用

的代码

我没有按预期看到我的屏幕事件,但我不确定这是否与我的代码有关或是GTM配置问题。

我发现了警告信息

1 个答案:

答案 0 :(得分:2)

使用GTM + Firebase实施时遇到了这个问题,只需在 viewDidAppear 方法中调用此方法即可消除警告:

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated);
        // ...
        Analytics.setScreenName(screenName, screenClass: screenClass)
    }
}

我希望这会有所帮助。