无法让GoogleMaps SDK在Xcode Test Target上工作(适用于App Target)

时间:2016-02-17 08:53:05

标签: ios swift google-maps-sdk-ios xctest

设置

我已使用CocoaPods成功将GoogleMaps SDK集成到我的Swift 2项目中。

我的设置几乎是Ray Wenderlich tutorial关于这个主题的建议。 我能找到的唯一区别是,我必须将此行添加到AppDelegate:

import UIKit
import GoogleMaps // <- THIS LINE

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate
{
    ...

...为了使用框架的类。教程建议导入:

#import <GoogleMaps/GoogleMaps.h>

...改为桥接标题。

该应用程序没有问题。

问题:

当我尝试运行Xcode自动生成的测试目标时,我收到错误:

  

没有这样的模块'GoogleMaps'

...指向上面AppDelegate中的swift import语句。

所以,我决定切换到教程中的方式:我在AppDelegate.swift中注释掉行import GoogleMaps,并在桥接头中添加一个Objective-C样式的import语句。

然而 ,我说错了:

  1. 如果我使用:#import <GoogleMaps/GoogleMaps.h>#import "GoogleMaps/GoogleMaps.h",它会给我:

      

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

    在构建应用目标时,在AppDelegate.swift上

  2. 如果我使用:#import "GoogleMaps.h",它会给我:

      

    'GoogleMaps.h':找不到文件

    在桥头处。

  3. 我在this answer尝试了解决方案,但结果(令人费解)相同......?

    接下来,我检查了两个目标(app和测试)的Build Settings / Search Paths / Framework Search Paths值。应用目标有条目:

    "${PODS_ROOT}/GoogleMaps/Frameworks"

    ...测试目标所缺少的,所以我添加了它,并恢复为swift风格的导入(至少在构建应用目标时起作用),但我仍然得到:

    import GoogleMaps   <! No such module 'GoogleMaps'
    

    如何为我的应用程序运行测试?

1 个答案:

答案 0 :(得分:3)

因此,事实证明我所要做的就是修复Podfile(并运行pod install),如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