Google Analytics不支持Swift 1.2和Xcode 6.3

con*_*ile 12 iphone google-analytics objective-c swift xcode6

我尝试使用Xcode 6.3beta在我的Swift 1.2应用程序中使用Google Analytics.

我的桥接头工作正常,包含:

#import "GAI.h"
#import "GAIDictionaryBuilder.h"
#import "GAIEcommerceFields.h"
#import "GAIEcommerceProduct.h"
#import "GAIEcommerceProductAction.h"
#import "GAIEcommercePromotion.h"
#import "GAIFields.h"
#import "GAILogger.h"
#import "GAITrackedViewController.h"
#import "GAITracker.h"
Run Code Online (Sandbox Code Playgroud)

我尝试了以下Swift代码来跟踪页面:

  var tracker2:GAITracker = GAI.sharedInstance().defaultTracker as GAITracker
  tracker2.set(kGAIScreenName, value:"Home Screen")
  tracker2.send(GAIDictionaryBuilder.createScreenView().build())
Run Code Online (Sandbox Code Playgroud)

但上面的最后一行引发了以下错误:

Cannot invoke 'send' with an argument list of type '(NSMutableDictionary!)'
Run Code Online (Sandbox Code Playgroud)

我发现了类似的问题,如:谷歌Analytics(分析)在雨燕未初始化,在iOS上使用谷歌Analytics(分析)与斯威夫特

我需要更改以使上面的代码与Swift 1.2一起使用?

Vid*_*era 24

我有同样的问题.以下是我如何使用它

let build = GAIDictionaryBuilder.createAppView().set(screenName, forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])
Run Code Online (Sandbox Code Playgroud)

  • `as [NSObject:AnyObject]`就足够了 (4认同)