在Swift 2或3中发布Google Analytics [英] Issue with Google Analytics in Swift 2 or 3

查看:127
本文介绍了在Swift 2或3中发布Google Analytics的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Swift 2(Swift 3)和Google Analytics(分析)中遇到了问题。

这是问题所在:

  tracker.send(GAIDictionaryBuilder.createScreenView()。build())



告诉我:


无法使用类型为'(NSMutableDictionary!)的参数列表调用'send' '



解决方案

更新为Swift 3(2016.10.19)

  let tracker = GAI.sharedInstance()。defaultTracker 
let build =(GAIDictionaryBuilder.createScreenView()。build )as NSDictionary)as! [AnyHashable:Any]
tracker?.send(build)

让我知道是否有更清晰的转换。






原始 $ b

同样在这里,努力解决大量的错误。



我做了什么(不推荐):

  var build = GAIDictionaryBuilder.createAppView()。build()as [NSObject:AnyObject] 
tracker.send(build)

编辑(2015)



感谢@George Poulos。 。最近他们更新了选项,现在createAppView已被弃用,应该使用createScreenView来代替。

  var build = GAIDictionaryBuilder.createScreenView()。build ()as [NSObject:AnyObject] 
tracker.send(build)


I have a problem with Swift 2 (Swift 3) and Google Analytics.

This is the line with the problem:

tracker.send(GAIDictionaryBuilder.createScreenView().build())

Xcode tell's me:

Cannot invoke 'send' with an argument list of type '(NSMutableDictionary!)'

解决方案

Update for Swift 3 (2016.10.19)

let tracker = GAI.sharedInstance().defaultTracker
let build = (GAIDictionaryBuilder.createScreenView().build() as NSDictionary) as! [AnyHashable: Any]
tracker?.send(build)

Still an ugly approach, let me know if there's an cleaner conversion.


Original

Same here, struggling to resolve tons of errors.

What I did (deprecated):

var build = GAIDictionaryBuilder.createAppView().build() as [NSObject : AnyObject]
tracker.send(build)

Edit (2015)

Thanks to @George Poulos. . Recently they updated the options, now createAppView is deprecated, should use createScreenView instead.

var build = GAIDictionaryBuilder.createScreenView().build() as [NSObject : AnyObject]
tracker.send(build)

这篇关于在Swift 2或3中发布Google Analytics的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆