ios - Google Analytics crash with Swift 2.0 -
i've installed googleanalytics
cocoapods
, tried use it, crashes error:
fatal error: unexpectedly found nil while unwrapping optional value
the crash occurs in part:
override func viewwillappear(animated: bool) { super.viewwillappear(animated) let tracker = gai.sharedinstance().defaulttracker tracker.set(kgaiscreenname, value: "main") let builder = gaidictionarybuilder.createscreenview() tracker.send(builder.build() [nsobject : anyobject]) }
and when reaching line:
tracker.set(kgaiscreenname, value: "main")
maybe has framework bridged objective-c?
update
so fixed crash wrapping if statment , still nothing sent google analytics:
let name = "main" if let gai = gai.sharedinstance() { if let tracker: gaitracker = gai.trackerwithtrackingid("tracking_id") { tracker.set(kgaiscreenname, value: name) let builder = gaidictionarybuilder.createscreenview() tracker.send(builder.build() [nsobject : anyobject]) print("tracker initialized") } }
the docs gai
class have defaulttracker
> convenience, class exposes default tracker instance. initialized nil , set first tracker instantiated in trackerwithtrackingid:. may overridden desired.
so i'm guessing need call trackerwithtrackingid:
somewhere, or if doing it, make sure happens before method called.
Comments
Post a Comment