无法让 GoogleMaps SDK 在 Xcode Test Target 上运行(在 App Target 上运行)
Can't get GoogleMaps SDK to work on Xcode Test Target (works on App Target)
设置
我已经使用 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 导入语句。
因此,我决定改用教程中的方式:我在 AppDelegate.swift 中注释掉行 import GoogleMaps
并添加一个 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 样式的导入(至少在构建应用程序目标时唯一有效的导入),但我仍然得到:
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
设置
我已经使用 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 导入语句。
因此,我决定改用教程中的方式:我在 AppDelegate.swift 中注释掉行 import GoogleMaps
并添加一个 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 样式的导入(至少在构建应用程序目标时唯一有效的导入),但我仍然得到:
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