ios - viewController.title is nil after init of Google analytics -


i followed google analytics doc add swift app

i have done said there, , yet code fails in run time.

here code in appdelegate:

func application(application: uiapplication, didfinishlaunchingwithoptions launchoptions: [nsobject : anyobject]?) -> bool {     loadgoogleanalytics()     chooseandluanchstoryboard()     initmembersafterviewcontrollerinit()     return true }  func loadgoogleanalytics() {     // configure tracker googleservice-info.plist.     var configureerror:nserror?     gglcontext.sharedinstance().configurewitherror(&configureerror)     assert(configureerror == nil, "error configuring google services: \(configureerror)")      // optional: configure gai options.     let gai = gai.sharedinstance()     gai.trackuncaughtexceptions = true  // report uncaught exceptions     gai.logger.loglevel = gailoglevel.error } 

here code in viewcontroller:

override public func viewwillappear(animated: bool) {     super.viewwillappear(true)      let name = "pattern~\(self.title!)"      // ua-xxxxx-y tracker id loaded automatically     // googleservice-info.plist `gglcontext` in appdelegate.     // if you're copying app using analytics, you'll     // need configure tracking id here.     // [start screen_view_hit_swift]     let tracker = gai.sharedinstance().defaulttracker     tracker.set(kgaiscreenname, value: name)      let builder = gaidictionarybuilder.createscreenview()     tracker.send(builder.build() [nsobject : anyobject])     // [end screen_view_hit_swift] }  override public func viewwilldisappear(animated: bool) {     keyboardmanager.deregisterfromkeyboardnotifications()     stoprefreshtimer() } 

i run-time error because self.title in let name = "pattern~\(self.title!)" nil

2016-02-05 19:44:44.377 inline[95803:3750273] configuration file 'googleservice-info.plist' bundle identifier ('com.inline.inline-ios'). using file services may not configured correctly. continue configuration file, may change app's bundle identifier 'com.inline.inline-ios'. or can download new configuration file matches bundle identifier https://developers.google.com/mobile/add , replace current one. 2016-02-05 19:44:44.383 inline[95803:] <gmr/info> app measurement v.1302000 started 2016-02-05 19:44:44.384 inline[95803:] <gmr/info> enable debug logging set following application argument: -gmrdebugenabled (see http://goo.gl/y0yjwu) 2016-02-05 19:44:45.999 inline[95803:] <gmr/info> app measurement enabled 2016-02-05 19:44:46.034 inline[95803:3750273] unknown class logo in interface builder file. 2016-02-05 19:44:46.048 inline[95803:3750273] failed set (keypath) user defined inspected property on (uiview): [<uiview 0x7faf9a079730> setvalue:forundefinedkey:]: class not key value coding-compliant key keypath. 2016-02-05 19:44:46.048 inline[95803:3750273] failed set (keypath) user defined inspected property on (uiview): [<uiview 0x7faf9a0729a0> setvalue:forundefinedkey:]: class not key value coding-compliant key keypath. 2016-02-05 19:44:46.048 inline[95803:3750273] failed set (keypath) user defined inspected property on (uiview): [<uiview 0x7faf9a07f8b0> setvalue:forundefinedkey:]: class not key value coding-compliant key keypath. 2016-02-05 19:44:46.051 inline[95803:3750273] device id: (null) 2016-02-05 19:44:46.051 inline[95803:3750273] registerdevice rpc request scanning beacons fatal error: unexpectedly found nil while unwrapping optional value 

how can make self.title non-nil?

init on didfinishlaunchingwithoptions

let gai = gai.sharedinstance() let id = "ua-id" gai.trackerwithtrackingid(id) gai.trackuncaughtexceptions = true gai.logger.loglevel = gailoglevel.warning gai.defaulttracker.allowidfacollection = false 

easy way call google analytics via setscreenname on viewdidappear.

extension uiviewcontroller {     func setscreename(name: string) {         self.title = name         self.sendscreenview()     }      func sendscreenview() {         let tracker = gai.sharedinstance().defaulttracker         tracker.set(kgaiscreenname, value: self.title)         let builder = gaidictionarybuilder.createscreenview()         tracker.send(builder.build() [nsobject : anyobject])     }      func trackevent(category: string, action: string, label: string, value: nsnumber?) {         let tracker = gai.sharedinstance().defaulttracker         let trackdictionary = gaidictionarybuilder.createeventwithcategory(category, action: action, label: label, value: value)         tracker.send(trackdictionary.build() [nsobject : anyobject])     } } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -