Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase IOS : Warning "setScreenName:screenClass: must be called after a view controller has appeared"

I want to understand the warning I am getting from Firbase IOS

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

My info.plist contains

FirebaseAutomaticScreenReportingEnabled = NO

I am calling

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

code taken from sample app

I am not seeing my screen event as expected but I am not sure whether this has anything to do with my code or is a GTM configuration issue.

I found the warning message ambigious

like image 398
Ryan Heitner Avatar asked Jan 12 '17 14:01

Ryan Heitner


1 Answers

Just faced this problem with a GTM + Firebase implementation and made the warning disappear simply by calling this method in the viewDidAppear method :

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

I hope this helps.

like image 121
n3wbie Avatar answered Oct 09 '22 14:10

n3wbie