Google Analytics 不适用于 Swift 1.2 和 Xcode 6.3 [英] Google Analytics not working with Swift 1.2 and Xcode 6.3

查看:25
本文介绍了Google Analytics 不适用于 Swift 1.2 和 Xcode 6.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I tried to use Google Analytics with my Swift 1.2 app using Xcode 6.3beta.

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

My bridging header works fine and contains:

#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 代码来跟踪页面:

I tried the following Swift code to track a page:

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

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

But the last line above raises the following error:

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

我发现了类似的问题,例如:Google Analytics 未在 Swift 中初始化在 iOS 上通过 Swift 使用 Google Analytics

I found similar questions like: Google Analytics not initialising in Swift, Using Google Analytics with Swift on iOS

我需要更改什么才能使上述代码与 Swift 1.2 一起使用?

推荐答案

我遇到了同样的问题.这是我如何让它工作

I had the same problem. Here is how I got it to work

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

这篇关于Google Analytics 不适用于 Swift 1.2 和 Xcode 6.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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