我终于在 SO 上找到了另一个处理类似问题的线程:通过 CocoaPods 添加 iOS 版 Google 地图的 Swift 项目中的链接器错误 https://stackoverflow.com/questions/28405079/linker-errors-in-a-swift-project-with-google-maps-for-ios-added-via-cocoapods.
这些错误似乎是由于错误的 Podspec 文件(在 Google Maps iOS SDK 端)和 Cocoapods 0.36 Beta 中的错误共同造成的。
实际上可以通过使用 @fz. 为 Google 地图修改的 Podspec 文件来解决这些问题:https://stackoverflow.com/a/28471830/145997 https://stackoverflow.com/a/28471830/145997。另一篇文章也对了解如何vendored_frameworks
设置工作于Podspec
is: http://codereaper.com/blog/2014/creating-a-pod-with-crashreporter/ http://codereaper.com/blog/2014/creating-a-pod-with-crashreporter/.
因此,要在 Pod 项目中正确导入 Google Maps iOS SDK,首先使用以下命令Podfile
:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
# altered version of Google's Podspec
pod 'Google-Maps-iOS-SDK', :podspec => "https://raw.githubusercontent.com/Reflejo/GoogleMapsPodspec/master/Google-Maps-iOS-SDK.podspec.json"
use_frameworks! # don't forget this!
我现在可以从我的 Swift 代码中引用 Google Maps 类,只需执行以下操作import GoogleMaps
。并且,为了分发 Pod,我的最后Podspec
现在类似于以下内容:
Pod::Spec.new do |s|
s.name = 'MyPod'
s.version = '1.0.0'
s.homepage = "https://github.com/..."
s.summary = '(pod summary)'
#s.screenshot = ""
s.author = { 'Romain L' => '(email)' }
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.social_media_url = "https://twitter.com/_RomainL"
s.platforms = { :ios => '8.0' }
s.ios.deployment_target = '8.0'
s.source_files = 'MyCode/*.{h,swift}'
s.module_name = 'MyPod'
s.source = { :git => "https://github.com/....git", :tag => "1.0.0" }
s.requires_arc = true
s.libraries = "c++", "icucore", "z" # required for GoogleMaps.framework
s.frameworks = "AVFoundation", "CoreData", "CoreLocation", "CoreText", "Foundation", "GLKit", "ImageIO", "OpenGLES", "QuartzCore", "SystemConfiguration", "GoogleMaps" # required for GoogleMaps.framework
s.vendored_frameworks = "Dependencies/GoogleMaps.framework" # Put the Google-provided framework in that subfolder of your Pod project
#s.dependency 'Google-Maps-iOS-SDK' # Careful! this will cause errors if enabled!
end
我现在可以在 Xcode 中启动一个新的 iOS 应用程序并使用以下命令Podfile
链接到我自己的 pod,它本身引用了 Google Maps iOS SDK:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'MyPod'
use_frameworks! # do not forget this!
不是那么容易,但毕竟是可行的!希望谷歌尽快修复它Podspec
不过,Swift 开发的文件。