捆绑包(标识:"org.cocoapods.MyPrivatePod")返回nil [英] Bundle(identifier: "org.cocoapods.MyPrivatePod") return nil

查看:44
本文介绍了捆绑包(标识:"org.cocoapods.MyPrivatePod")返回nil的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问我的私人Pod捆绑包,但始终返回nil.

I would like to access to my private pod bundle, but always return nil.

Bundle(identifier: "org.cocoapods.MyPrivatePod")//only this return nil
Bundle(identifier: "org.cocoapods.Alamofire")
Bundle(identifier: "org.cocoapods.SQLCipher")

我的podspec

Pod::Spec.new do |s|
  s.name                  = 'MyPrivatePod'
  s.version               = '1.4.0'
  s.summary               = 'MyPrivatePod Component'
  s.description           = "MyPrivatePod."
  s.homepage              = 'https://github.com/myprivatecompany/myprivtepodrepo.git'
  s.license               = ""
  s.authors               = { 'me me' => 'me@me.com' }
  s.swift_version         = '4.2'
  s.source                = { :git => "git@github.com:myprivatecompany/myprivtepodrepo.git", :tag => "#{s.version}" }
  s.ios.deployment_target = '9.0'
  s.source_files          = 'MyPrivatePod/**/*.{h,m,swift}'
  s.resource_bundles      = {
    "MyPrivatePod" => ['MyPrivatePod/**/*.{xcassets,ttf,strings,json,xib,gif,storyboard}']
    }
  #s.resources        = 'MyPrivatePod/**/*.{xcassets,ttf,strings,json,xib,storyboard}'
  s.static_framework      = true
  s.dependency 'AnotherPrivatePod', '2.3.0'
end

推荐答案

问题是您将 MyPrivatePod 定义为podspec中的静态框架:

The problem is that you are defining MyPrivatePod as a static framework in your podspec:

s.static_framework      = true

当您使用静态框架时,编译器将在应用程序二进制文件中包含该框架所需的代码,并且不会将该框架捆绑在应用程序包中.这意味着在运行时,您的应用程序中的代码与框架中的代码之间不会有任何区别.

When you use a static framework the compiler will include the code you need from that framework in your app binary and won't bundle that framework in the app package. This means that in run time there won't be any difference between the code in your app and the code in the framework.

既然是这种情况,请使用类似以下内容的

Since this is the case, using something like:

let podBundle = Bundle(for: SomeClassFromPod.self)

实际上将返回应用程序捆绑包,因为 SomeClassFromPod 在编译时已作为应用程序二进制文件的一部分包含在内.

will actually return the app bundle, because SomeClassFromPod was included as as part of the app binary at compile time.

如果仅在框架中包含代码,那么我认为没有任何需要引用该捆绑软件的用例.如果您还包括代码以外的其他资源,则有两个选项可以访问它们:

If you only include code in your framework, I can't think of any use case for needing a reference to that bundle. If you also include some resources other than the code, you have two options to access them:

  1. 构建您的框架并将其包含为动态框架.这样做的缺点是,您将在应用程序启动时引发与包含动态框架相关的性能问题.
  2. 继续将该框架用作静态框架,然后手动将该框架中的资源复制到您的应用程序包中.为此,您可以在主应用程序的构建阶段中添加一个 New Copy Files阶段(仅当手动包含框架时才需要这样做).完成此操作后,您可以访问这些资源,就像它们首先属于您的主捆绑包一样.这样做的问题在于,不同捆绑中具有相同名称的资源会发生冲突.
  1. Build and include your framework as a dynamic framework. The drawback of doing this is that you will incur in the performance issues at app launch time associated to including dynamic frameworks.
  2. Continue using the framework as a static framework and manually copy the resources in that framework to your app bundle. You can do this by adding a New Copy Files Phase in the build phases of your main app (You need to do this only when including the framework manually). After doing this you can access those resources as you would do if they belonged to your main bundle in the first place. The problem with doing this is that resources with the same name in different bundles would collide.

这篇关于捆绑包(标识:"org.cocoapods.MyPrivatePod")返回nil的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆