簡體   English   中英

帶有Swift 3 iOS 9的Google Analytics(分析)

[英]Google Analytics with Swift 3 iOS 9

我試圖找到有關如何在Swift 3中使用Google Analytics(分析)的信息,即使看起來有些成功,我也無法自己使用。

Google Analytics(分析)文檔無濟於事,僅適用於Swift 2。

我在3.17.0版中使用了“ Google / Analytics”廣告連播,並嘗試將這一行添加到橋接頭文件中,就像有人提到的那樣:

#import <Google/Analytics.h>

但是我遇到了一個關於Xcode的錯誤,抱怨橋接標頭在Swift 3中不起作用。

然后,我嘗試在.h內添加同一行,如另一篇文章所建議的那樣,但兩者都不起作用,Xcode抱怨“框架模塊XXX內包含非模塊化標頭”。

我試圖將“允許框架模塊中的非模塊化包含”設置為“是”,但它沒有任何改變,仍然出現相同的錯誤。

我嘗試的最后一件事是添加:

import Google

在我使用Google Analytics(分析)的文件中,但現在無法識別GAI。

// Configure tracker from GoogleService-Info.plist.
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \(configureError)")

// Optional: configure GAI options.
guard let gai = GAI.sharedInstance() else {
    assert(false, "Google Analytics not configured correctly")
}
gai.trackUncaughtExceptions = true  // report uncaught exceptions
gai.logger.logLevel = GAILogLevel.verbose  // remove before app release

有什么建議么 ?

請按照以下步驟配置Google Analytics(分析)

  1. 在Google Analytics(分析)上創建一個項目,然后下載配置文件“ GoogleService-Info.plist”
  2. 使用Pod將Google Analytics(分析)安裝到您的項目中(確保終端中顯示錯誤)
  3. 清除並關閉項目,然后導航到項目文件夾,然后打開“ XXX.xcworkspace ”,而不是“ XXX.xcodeproj ”。
  4. 然后將“ GoogleService-Info.plist ”添加到您的項目中(如果需要,請選中“復制”)。
  5. 如果項目中已經存在一個橋接文件,則無需重新創建它。

    5.1。 要創建橋接文件,最簡單的方法是在項目中添加/創建新的Objective-C類,並彈出選項,要求您創建橋接文件,並且默認情況下設置所有設置。

  6. 打開通常名為“ YourProjectName-Bridging-Header.h ”的橋接文件,然后在其中復制" #import <Google/Analytics.h> "
  7. 打開“ AppDelegate.swift ”,然后將以下代碼復制並粘貼到didFinishLaunchingWithOptions中,以設置Google Analytics(分析)跟蹤器

     // Configure tracker from GoogleService-Info.plist. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \\(configureError)") // Optional: configure GAI options. guard let gai = GAI.sharedInstance() else { assert(false, "Google Analytics not configured correctly") } gai.trackUncaughtExceptions = true // report uncaught exceptions gai.logger.logLevel = GAILogLevel.verbose // remove before app release 
  8. 建立您的專案。

我希望如果有任何問題,請告訴我。

我遇到了同樣的問題。 由於Xcode生成錯誤,我無法導入“ Google / Analytics.h”標頭。 因為Google的官方頁面中提到的“ GoogleAnalytics sdk”中沒有“ Google / Analytics.h”標頭。 所以,我只是在AppDelegete.m文件中使用了以下行

#import "AppDelegate.h"
#import "GAI.h"

希望它會很好。 環境Xcode:8.2 iOS:10.2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM