【问题标题】:Google Analytics not working with Swift 1.2 and Xcode 6.3 [duplicate]Google Analytics 不适用于 Swift 1.2 和 Xcode 6.3 [重复]
【发布时间】:2015-04-12 16:48:52
【问题描述】:

我尝试在使用 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 SwiftUsing Google Analytics with Swift on iOS

要使上述代码与 Swift 1.2 一起使用,我需要进行哪些更改?

【问题讨论】:

    标签: objective-c iphone swift google-analytics xcode6


    【解决方案1】:

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

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

    【讨论】:

    • as [NSObject : AnyObject] 就够了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    相关资源
    最近更新 更多