问题
The Setup
I have successfully integrated the GoogleMaps SDK into my Swift 2 project using CocoaPods.
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>
...to the bridging header instead.
The app works without problems.
The Problem:
When I tried to run the test target auto-generated by Xcode, I get the error:
No such module 'GoogleMaps'
...pointing at the to the swift import statement in AppDelegate above.
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:
If I use:
#import <GoogleMaps/GoogleMaps.h>
or#import "GoogleMaps/GoogleMaps.h"
, it gives me:Use of unresolved identifier 'GMServices'
at AppDelegate.swift when building the app target.
If I use:
#import "GoogleMaps.h"
, it gives me:'GoogleMaps.h': file not found
at the bridging header.
I have tried the solution in this answer, but the results are (puzzlingly) the same...?
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'
How can I run tests for my app??
回答1:
So, it turns out all I had to do is fix the Podfile (and run pod install
), as explained in this answer.
My old pod file:
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
My current pod file:
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
来源:https://stackoverflow.com/questions/35451837/cant-get-googlemaps-sdk-to-work-on-xcode-test-target-works-on-app-target