我正在遵循Analytics for iOS(developers.google.com/analytics/devguides/collection/ios/v3/?ver=swift)指南,但我的Swift代码项目中存在无法修复的错误。 我正在使用XCode 6.4、Swift和iOS Deployment Target 8.1。
步骤1
首先,我使用CocoaPods安装了Google 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
按照指南所说,打开我的应用程序的 Project .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是我的项目名称。
第三步
我获取了配置文件GoogleService-Info.plist
,并将其添加到项目中的所有目标(我的项目中有2个目标)。
第四步
我通过选择文件>新建>文件>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
现在有些问题: 我尝试将Google Analytics包含/导入到我的AppDelegate.swift中,但无法做到。出现了这个错误:
AppDelegate.swift import Google Analytics
我还尝试过import "Google/Analytics.h"
但是另一个错误出现了:Expected identifier in import declaration
。
- 我该怎么解决这个问题,使XCode不会给我出错?
- BridgingHeader是否有误?我是否需要以某种方式指向它来识别其内部头文件?
- 除了目前缺少的Google Analytics配置外,我是否还需要配置其他内容?
非常感谢。