pod'GoogleAnalytics'在swift 4中不会运行 [英] pod 'GoogleAnalytics' in swift 4 won't run

查看:148
本文介绍了pod'GoogleAnalytics'在swift 4中不会运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了此说明,以在我的应用中使用Google Analytics(分析)
https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift
,因此我将pod'GoogleAnalytics'安装到了我的应用中,并创建了一个.h文件在我的swift应用程序中
所以这里是我的应用程序中的h文件代码

pre $#$#$#$#$#$#$#$#$#$解析分析
#define analytic_h
#import< Google / Analytics.h>

#endif / * analytic_h * /

这里是我的应用程序Delegate代码但这段代码无法识别GAI

  func应用程序(_ application:UIApplication,didFinishLaunchingWithOptions launchOptions:[UIApplicationLaunchOptionsKey:Any]?) - > Bool {
//在应用程序启动后替代自定义点。
$ b $ guard gai = GAI.sharedInstance()else {
assert(false,Google Analytics配置不正确)
}
gai.tracker(withTrackingId: UA-xxxxxxxxx-x)
//可选:自动报告未捕获的异常。
gai.trackUncaughtExceptions = true

//可选:将记录器设置为VERBOSE以获取调试信息。
//在应用发布之前删除。
gai.logger.logLevel = .verbose;

返回true
}

我收到GAI


使用未解析的标识符'GAI'


解决方案

我对此的研究 -



案例1-手动添加桥接头

我在项目中添加了名为MyProject-Bridging-Header.h的.h文件。
我收到了一个包含内容的文件 -


  #ifndef MyProject-Bridging-Header_h 
#define MyProject -Bridging-Header_h


#endif / * MyProject-Bridging-Header_h * /

然后我尝试添加以下其中一项 -

  #import< GAI.h> 
#import< Google / Analytics.h>

但他们都没有工作。

案例2 - 自动添加桥接头



为此,我添加了Objective-C文件,并提示自动添加桥接头并接受。在这个桥接头文件中,我添加了

  #import< GAI.h> 

然后它就像一个魅力一样,然后,我删除了上面的行并添加 -

  #import< Google / Analytics.h> 

无法找到Google / Analytics.h。


I read this instructions to use google analytics in my app https://developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift so I installed pod 'GoogleAnalytics' into my app and created a .h file in my swift application so here is my h file codes in my app

#ifndef analytic_h
#define analytic_h
#import <Google/Analytics.h>

#endif /* analytic_h */

and here is my app Delegate codes But this code does not recognize GAI

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    guard let gai = GAI.sharedInstance() else {
        assert(false, "Google Analytics not configured correctly")
    }
    gai.tracker(withTrackingId: "UA-xxxxxxxxx-x")
    // Optional: automatically report uncaught exceptions.
    gai.trackUncaughtExceptions = true

    // Optional: set Logger to VERBOSE for debug information.
    // Remove before app release.
    gai.logger.logLevel = .verbose;

    return true
}

I received this error for GAI

Use of unresolved identifier 'GAI'

解决方案

My research on this-

Case 1- Adding Bridging header manually

I added .h file with name "MyProject-Bridging-Header.h" in the project. And I received a file having content-

#ifndef MyProject-Bridging-Header_h
#define MyProject-Bridging-Header_h


#endif /* MyProject-Bridging-Header_h */

And then I tried adding one of the followings-

#import <GAI.h>
#import <Google/Analytics.h>

But none of them were working.

Case 2 - Adding bridging header automatically

For this, I added "Objective-C File" and it gave a prompt to add bridging header automatically and I accepted. In that bridging header file, I added

 #import <GAI.h>

then it built like a charm and after that, I removed the line above and added -

#import <Google/Analytics.h>

It failed saying Google/Analytics.h not found.

这篇关于pod'GoogleAnalytics'在swift 4中不会运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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