ios – 用Swift构建Cocoapod并依赖Objective-C框架

前端之家收集整理的这篇文章主要介绍了ios – 用Swift构建Cocoapod并依赖Objective-C框架前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我知道这个主题在这方面已经有几个问题,但很少有人接受答案,我不认为我发现了和我一样的问题.

我正在构建一个Swift pod,在我的代码中,我依靠的是谷歌地图iOS SDK,它被捆绑为一个.framework文件.该项目在Xcode中建立起来,但是我有麻烦将lib发布到Cocoapods.

我设法有一个Podspec文件,几乎使用pod lib lint命令进行验证.但是,现在我已将Google-Maps-iOS-SDK pod作为依赖关系添加到Podspec文件中,它会失败,并显示以下消息:

$pod lib lint

[!] The ‘Pods’ target has transitive dependencies that include static
binaries:
(/private/var/folders/n2/qyjfpk6n7zz_mngtwswlmsy00000gn/T/CocoaPods/Lint/Pods/Google-Maps-iOS-SDK/GoogleMaps.framework)

$

这是预期的吗为什么我无法在我自己的基于Swift的pod中添加Google Maps iOS SDK作为pod参考?

这是Podspec:

Pod::Spec.new do |s|
s.name                  = '(name)'
s.version               = '1.0.0'
s.summary               = '(summary)'
s.platforms             = { :ios => '8.0',:osx => '10.10' }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.10'
s.license               = { :type => 'BSD',:file => 'LICENSE' }
s.source_files          = 'Sources/*.{h,swift}','*.framework'
s.source                = { :git => "https://github.com/(Github repo).git",:tag => "1.0.0" }
s.requires_arc          = true
s.frameworks             = "Foundation","CoreLocation"
s.author                = { 'Romain L' => '(email)' }
s.dependency 'Google-Maps-iOS-SDK'
end

如果我没有将Google Maps iOS SDK作为依赖关系,那么pod lib lint在桥接头中失败,并且抱怨找不到< GoogleMaps / GoogleMaps.h> (文件未找到).

我被卡住了,我不知道这是否是Cocoapods 0.36(仍然是Beta版)的错误,或者我做错了.

谢谢你的帮助!

解决方法

我终于在SO上找到了另一个线程,处理类似的问题: 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.另外一篇文章,也是非常感兴趣的了解在Podspec中的vendered_frameworks设置是如何工作的: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!

我现在可以通过简单的导入Google地图,从Swift代码中引用Google Maps类.而且,为了分发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!

毕竟不是那么容易,但可行希望谷歌即将推出适用于Swift开发的Podspec文件.

原文链接:https://www.f2er.com/iOS/330709.html

猜你在找的iOS相关文章