我按照此处的说明将谷歌分析集成到我的应用程序中:https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift#get-config
我现在需要为我的应用程序初始化分析。我已将此代码添加到我的 AppDelegate.swift 文件中:
import UIKit
import <Google/Analytics.h>
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool {
**// Configure tracker from GoogleService-Info.plist.
NSError *configureError;
[[GGLContext sharedInstance] configureWithError:&configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
// Optional: configure GAI options.
GAI *gai = [GAI sharedInstance];
gai.trackUncaughtExceptions = YES; // report uncaught exceptions
gai.logger.logLevel = kGAILogLevelVerbose; // remove before app release**
}
我收到以下错误消息。
给我的
import <Google/Analytics.h>
行时,我收到此消息:“一行中的连续语句必须用 ';' 分隔。对于代码的其余部分,尽管我只是将教程中的代码复制到我的文件中,但我遇到了几个错误。请参阅我的屏幕截图。
最佳答案
由于您处于 Swift 项目中,因此您会遇到此问题。您需要创建一个 Objective-C 桥接 header ,并在其中添加导入语句。之后,一切都应该正常工作。查看此答案以了解更多详细信息:
关于ios - 将谷歌分析集成到 iOS 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36270707/