我有一个新项目,我在其中使用 XCode 7 beta 3 和 Swift 2.0,使用通过 cocoapods 导入的 GoogleMaps。这是一个 WatchKit 2.0 应用程序,所以我有一个 iPhone 的主要目标(Destinations),一个 Apple Watch 的目标(Destinations WatchKitApp 和 Destinations WatchKitExtension)和一个内部框架(DestinationsKit),它负责与 GoogleMaps 进行交互其他事情。
我可以成功将 GoogleMaps 导入到主要目标(Destinations)并成功显示 map 。
import UIKit
import DestinationsKit
import GoogleMaps
class DestinationDetailsViewController : UIViewController
{
// our selected destination
var destination: Destination!
// our map view
var mapView : GMSMapView!
// ... code to display a map centering on the destination ...
}
上面的代码导入了我的内部框架 DestinationsKit,并成功地使用了 GoogleMaps。
但是,我现在正在编写计算两点之间路线的代码,并将该代码添加到内部框架 (DestinationsKit) 中。每当我尝试导入 GoogleMaps 时,我都会收到“没有这样的模块‘GoogleMaps’”。
import Foundation
import CoreLocation
import GoogleMaps // Error 'No such module 'GoogleMaps''
public class UserTrip {
}
我做了以下但没有成功:
- “在构建阶段”->“将二进制文件与库链接”,我添加了 Pods.Framework(这是我在主要目标中成功所做的)
- 将“允许非模块化包含在框架模块中”设置为"is"
- 在build设置中将 'Packaging'->'Defines Module' 设置为 Yes
我的Pod文件如下:
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!
pod 'GoogleMaps'
我确保 Pods.Framework 包含在两个目标中。所以,我无法弄清楚为什么主要目标可以找到 GoogleMaps,但我的内部框架却找不到。
提前致谢!
最佳答案
当然,一旦我发布问题,我就会找出原因。
即使我手动将 Pods.framework 添加到构建阶段,我也需要更新我的 Pods 文件以将框架作为目标包括在内,然后再次运行“pod install”。因此,更新后的 Pod 文件为:
source 'https://github.com/CocoaPods/Specs.git'
# We need to link with all targets. If target is added, this must be updated
use_frameworks!
pod 'GoogleMaps'
link_with 'Destinations', 'DestinationsKit'
target 'Destinations' do
end
target 'DestinationsKit' do
end
不确定“目标”行是否是必需的,但最好包括在内,以便特定于目标的依赖项有一个家。
关于ios - 无法将 GoogleMaps 导入 Xcode 7 中的框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31482925/