我尝试使用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"
我尝试使用以下Swift代码来跟踪页面:
var tracker2:GAITracker = GAI.sharedInstance().defaultTracker as GAITracker
tracker2.set(kGAIScreenName, value:"Home Screen")
tracker2.send(GAIDictionaryBuilder.createScreenView().build())
但上面的最后一行引发了以下错误:
Cannot invoke 'send' with an argument list of type '(NSMutableDictionary!)'
我发现了类似的问题:Google Analytics not initialising in Swift,Using Google Analytics with Swift on iOS
我需要更改什么才能使上面的代码与Swift 1.2一起使用?
答案 0 :(得分:24)
我遇到了同样的问题。以下是我如何使用它
let build = GAIDictionaryBuilder.createAppView().set(screenName, forKey: kGAIScreenName).build() as NSDictionary
tracker.send(build as [NSObject : AnyObject])