设置
我已经使用 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 自动生成的测试目标时,出现错误:
No such module 'GoogleMaps'
...指向上面 AppDelegate 中的 swift import 语句。
因此,我决定改用教程中的方式:我注释掉 import GoogleMaps
这行在 AppDelegate.swift 中,将 Objective-C 风格的导入语句添加到桥接头文件中。
但是,我做不对:
如果我使用:
#import <GoogleMaps/GoogleMaps.h>
或#import "GoogleMaps/GoogleMaps.h"
,它给了我:Use of unresolved identifier 'GMServices'
在构建应用程序目标时在 AppDelegate.swift 中。
如果我使用:
#import "GoogleMaps.h"
,它给了我:'GoogleMaps.h': file not found
在桥接头处。
我已经尝试了 this answer 中的解决方案,但结果(令人费解地)是一样的...?
接下来,我检查了 Build Settings / Search Paths / Framework Search Paths
的值对于两个目标(应用程序和测试)。应用目标有条目:
"${PODS_ROOT}/GoogleMaps/Frameworks"
...测试目标缺少它,所以我添加了它,并恢复为 swift-style 导入(唯一至少在构建应用程序目标时有效的导入),但我仍然得到:
import GoogleMaps <! No such module 'GoogleMaps'
如何为我的应用运行测试?
最佳答案
所以,事实证明我所要做的就是修复 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
关于ios - 无法让 GoogleMaps SDK 在 Xcode Test Target 上运行(在 App Target 上运行),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35451837/