无法使GoogleMaps SDK在Xcode Test Target上运行(在App Target上运行)
我已经使用CocoaPods成功地将GoogleMaps SDK集成到了我的Swift 2项目中.
I have successfully integrated the GoogleMaps SDK into my Swift 2 project using CocoaPods.
我的设置几乎是 Ray Wenderlich教程建议的. 我能找到的唯一区别是,我必须将此行添加到AppDelegate:
My setup is pretty much that suggested by the Ray Wenderlich tutorial on the subject. The only difference I can find is, I have to add this line to AppDelegate:
import UIKit
import GoogleMaps // <- THIS LINE
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
...
...以便使用框架的类.本教程建议导入:
...in order to use the framework's classes. The tutorial suggests importing:
#import <GoogleMaps/GoogleMaps.h>
...改为桥接头.
该应用程序正常运行.
当我尝试运行Xcode自动生成的测试目标时,出现错误:
When I tried to run the test target auto-generated by Xcode, I get the error:
没有此类模块"GoogleMaps"
No such module 'GoogleMaps'
...指向上面AppDelegate中的swift import语句.
...pointing at the to the swift import statement in AppDelegate above.
因此,我决定改用本教程中的方式:我在AppDelegate.swift中注释掉import GoogleMaps
行,并在桥接标题中添加一个Objective-C风格的导入语句.
So, I decide to switch to the way it is in the tutorial instead: I comment out the line import GoogleMaps
in AppDelegate.swift and add an Objective-C-style import statement to the bridging header.
但是 ,我无法正确理解:
However, I can not get it right:
-
如果我使用:
#import <GoogleMaps/GoogleMaps.h>
或#import "GoogleMaps/GoogleMaps.h"
,它会给我:
使用未解析的标识符"GMServices"
Use of unresolved identifier 'GMServices'
在构建应用程序目标时位于AppDelegate.swift.
at AppDelegate.swift when building the app target.
如果我使用:#import "GoogleMaps.h"
,它会给我:
If I use: #import "GoogleMaps.h"
, it gives me:
'GoogleMaps.h':找不到文件
'GoogleMaps.h': file not found
在桥接头.
我已经在此答案中尝试了该解决方案,但结果(令人费解)是相同的??
I have tried the solution in this answer, but the results are (puzzlingly) the same...?
接下来,我检查了两个目标(应用程序和测试)的Build Settings / Search Paths / Framework Search Paths
值.该应用目标具有以下条目:
Next, I checked the value of Build Settings / Search Paths / Framework Search Paths
for both targets (app and tests). The app target had the entry:
"${PODS_ROOT}/GoogleMaps/Frameworks"
...测试目标所缺少的,所以我添加了它,并恢复为快速样式导入(至少在构建应用目标时有效的唯一输入),但我仍然得到:
...which the test target lacked, so I added it, and reverted to the swift-style import (the only one that works at least when building the app target), but I still get:
import GoogleMaps <! No such module 'GoogleMaps'
如何为我的应用运行测试?
因此,事实证明,我要做的就是修复Podfile(并运行pod install
),如
So, it turns out all I had to do is fix the Podfile (and run pod install
), as explained in this answer.
我的旧Pod文件:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
def import_pods
pod 'GoogleMaps'
end
workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'
target : MyApp do
xcodeproj 'MyApp MyApp.xcodeproj'
pod 'GoogleMaps'
end
我当前的pod文件:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.1'
def import_pods
pod 'GoogleMaps'
end
workspace 'MyWorkspace'
xcodeproj 'MyApp/MyApp.xcodeproj'
target 'MyApp', :exclusive => true do
xcodeproj 'MyApp/MyApp.xcodeproj'
import_pods
end
target 'MyAppTests', :exclusive => true do
xcodeproj 'MyApp/MyApp.xcodeproj'
import_pods
end