我正在关注iOS的Analytics(developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift)指南,并且我在我的Swift代码项目中出现错误我无法修复。 我正在使用XCode 6.4,Swift和iOS部署目标8.1。在ios swift中实现Google Analytics
步骤1
首先,我使用的CocoaPods安装了谷歌SDK。 这是运行pod install
命令后,控制台结果:
Updating local specs repositories
CocoaPods 1.0.0.beta.2 is available.
To update use: `gem install cocoapods --pre`
[!] This is a test version we'd love you to try.
For more information see http://blog.cocoapods.org
and the CHANGELOG for this version http://git.io/BaH8pQ.
Analyzing dependencies
Downloading dependencies
Using Google (1.0.7)
Using GoogleAnalytics (3.14.0)
Using GoogleNetworkingUtilities (1.0.0)
Using GoogleSymbolUtilities (1.0.3)
Using GoogleUtilities (1.1.0)
Generating Pods project
Integrating client project
Sending stats
Pod installation complete! There is 1 dependency from the
Podfile and 5 total pods installed.
步骤2
然后打开,在引导,我的应用程序的项目.xcworkspace文件说。
我Podfile看起来是这样的:
# Uncomment this line to define a global platform for your project
# platform :ios, '8.0'
# Uncomment this line if you're using Swift
# use_frameworks!
target 'XXXXXX' do
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
pod 'Google/Analytics', '~> 1.0.0'
end
target 'XXXXXXTests' do
pod 'Google/Analytics', '~> 1.0.0'
end
其中XXXXXX是我的项目的名称。
步骤3
我得到的配置文件GoogleService-Info.plist
并列入我的计划将所有的目标(2个目标在我的项目)。
步骤4
我通过选择文件>新建>文件>的iOS>来源>头文件创建的BridgingHeader
通过。 我将它命名为BridgingHeader.h
,它位于我的项目的根目录中。 内容是:
#ifndef XXXXX_BridgingHeader_h
#define XXXXX_BridgingHeader_h
#import "Google/Analytics.h"
#import <Google/Analytics.h>
#include "GAI.h"
#import <CoreData/CoreData.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import "Libraries/GoogleAnalytics/GAI.h"
#import "Libraries/GoogleAnalytics/GAIFields.h"
#import "Libraries/GoogleAnalytics/GAILogger.h"
#import "Libraries/GoogleAnalytics/GAITracker.h"
#import "Libraries/GoogleAnalytics/GAIDictionaryBuilder.h"
#endif
其中 “XXXXX” 是我的项目的名字。
步骤5
现在的问题: 我想包括/导入谷歌分析了我的AppDelegate.swift,但我不能。这是错误:
AppDelegate.swift import Google Analytics
我也试过import "Google/Analytics.h"
但出现另一个错误:Expected identifier in import declaration
。
- 我怎样才能解决这个如此的XCode不给我的错误?
- BridgingHeader是否错误?我是否必须以某种方式指出它的内部标题?
- 我是否必须为我现在缺少的Google Analytics配置其他内容?
非常感谢。
我想在我的框架目标中使用GoogleAnalytics。问题是框架目标不支持桥接头,并且上面的两个pod都不适用于我。你有任何建议,使其工作? – user1615898
@ user1615898,我认为你有两个选择:1)使用Firebase分析。它不需要创建桥接头。 2)您可以使用Google Analytics服务SDK 手动设置Google Analytics。 更多的信息和说明在这里: https://developers.google.com/analytics/devguides/collection/ios/v3/sdk-download –