Swift   发布时间:2022-04-29  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法使用cocoapods在watchKit 2.0中加载动态库大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
无法使用我安装的 CocoaPods成功运行WatchKit应用程序,并且正在获取“dyld:未加载库…原因:未找到图像”错误.

环境如下:@L_696_3@ 2.0,WatchKit 2.0,CocoaPods 0.38.2,Xcode 7 Beta 4,项目使用我开发的一些内部CocoaPods,用于带有WatchKit扩展的iPhone应用程序.

我已经构建了许多内部使用的CocoaPods,它们包含我想从我的主应用程序和WatchKit扩展中调用的公共代码.下面是Podfile:

source 'https://github.com/CocoaPods/Specs.git'
source 'http://<local-git>/podspecs.git'

use_frameworks!

target 'DesTinations511' do
  platform :ios,'9.0'

  pod 'GoogleMaps'
  pod 'APIKit',:path => '~/Documents/Libraries/APIKit'
  pod 'DesTinationsKit',:path => '~/Documents/Libraries/DesTinationsKit'
end

target 'DesTinations511 WatchKit Extension' do
   platform :watchos,'2.0'

   pod 'APIKit',:path => '~/Documents/Libraries/APIKit'
   pod 'DesTinationsKit',:path => '~/Documents/Libraries/DesTinationsKit'
end

我可以构建我的主应用程序,它按预期运行.我可以编译监视工具包应用程序,但是当它运行时,我得到以下内容

dyld: Library not loaded: @rpath/APIKit.framework/APIKit Referenced from (...) Reason: image not found.

我尝试过针对其他dylib问题提到的解决方案,包括

>确保我的Target-> Build SetTings-> Runpath搜索路径包括@ executable_path / Frameworks
>尝试将APIKit.framework添加到Target-> General->嵌入式二进制文件(由于某种原因,我选择它时甚至不会添加框架)
>由Podfile解体并重建它.
>将APIKit.framework添加到Target-> General-> Linked Frameworks and Libraries

当我在xcode中查看我的Pods目录时,我看到每个Framework的两个实例(我假设是因为有一个用于应用程序,一个用于监视).即使我成功构建并运行iPhone应用程序,它们都会保持红色.

可能相关,但不确定如何解决,是当我编译(无论目标)时,我得到了一些警告:

ld: warning: linking against dylib not safe for use in application extensions: /Users/dan/Library/Developer/Xcode/DerivedData/MyProject-dlixiemzyqyquocjthlseirhdxcm/Build/Products/Debug-watchsimulator/Pods_MyProject_WatchKit_Extension.framework/Pods_MyProject_WatchKit_Extension

为了完成,这里是APIKit的PodSpec

Pod::Spec.new do |s|

  s.name         = "APIKit"
  s.version      = "1.1"
  s.sumMary      = "APIKit provides the basic classes and methods common to a number of our apps"

  s.homepage     = "http://.../apikit.git"
  s.license      = { :type => "MIT",:file => "LICENSE" }
  s.author             = { "me" => "me@me.com" }

  s.platform     = :ios
  s.ios.deployment_target = "9.0"
  s.watchos.deployment_target = "2.0"

   s.source       = { :git => "http://my-git-LOCATIOn/apikit.git",:tag => "#{s.version}" }

  s.source_files  = "APIKit"

  s.frameworks = "UIKIt","CoreLOCATIOn"

  s.requires_arc = true

end

解决方法

这有点违反直觉,当您安装/更新pod时会导致CocoaPods发出警告,但我通过在WatchKit Extension的构建设置中将EMBEDDED_CONTENT_CONTAINS_SWIFT设置为NO来解决此问题,即使它包含Swift.该应用程序仍然运行,它在App Store中,但CocoaPods仍然警告我这个设置.

大佬总结

以上是大佬教程为你收集整理的无法使用cocoapods在watchKit 2.0中加载动态库全部内容,希望文章能够帮你解决无法使用cocoapods在watchKit 2.0中加载动态库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。