gpt4 book ai didi

swift - 无法在 Today Extension 上使用 AFNetworking

转载 作者:可可西里 更新时间:2023-10-31 23:44:19 28 4
gpt4 key购买 nike

我正在努力让 AFNetworking 在我的 Today Extension 上工作。

我的应用程序是一个带有 cocoapods (0.39.0) 的 Objective-c 项目,我在其中开始将一些东西迁移到 Swift。我成功地使 Swift 与 Objective-C 一起工作,并且我在 Swift 和 Objective-C 代码中都使用了 AFNetworking。

我添加了 Today Extension(用 Swift 制作),当我尝试使用使用 AFNetworking 的 Swift 类时,它提示找不到“AFHTTPRequestOperationManager”和其他 AFNetworking 相关类。

我尝试了 Podfile 的不同解决方案,目前配置如下:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'

def testing_pods
pod 'Google/Analytics', '~> 1.0.0'
pod 'AFNetworking', '~> 2.6'
pod 'XCDYouTubeKit', '~> 2.4.0'
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
pod 'FBSDKLoginKit'
pod 'Parse'
pod 'ParseUI'
pod 'ParseFacebookUtilsV4'
pod 'ParseTwitterUtils'
end

target '***' do

testing_pods

end

target '***' do

testing_pods

end

target 'todayExtension' do
pod 'AFNetworking', '~> 2.6'
end

post_install do |installer_representation|
installer_representation.pods_project.targets.each do |target|
puts "=== #{target.name}"
if target.name == "AFNetworking"
puts "Setting AFNetworking Macro AF_APP_EXTENSIONS so that it doesn't use UIApplication in extension."
target.build_configurations.each do |config|
puts "Setting AF_APP_EXTENSIONS macro in config: #{config}"
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'AF_APP_EXTENSIONS']
end
end
target.build_configurations.each do |config|
puts "Setting only_active_arch in config: #{config}"
config.build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
end
end
end

我已经删除了所有 pod 和工作区并重新创建它们,但问题仍然存在。

有什么建议吗?

谢谢

最佳答案

默认 cocoapods 为 pod 创建静态库,但 swift 不支持静态库。因此,要在 swift 中使用 cocoapods,您应该指定使用动态框架。为此,请在您的 Podfile

中包含以下行
use_frameworks!

了解更多信息

https://blog.cocoapods.org/CocoaPods-0.36/

http://www.raywenderlich.com/97014/use-cocoapods-with-swift

更新另请注意,AFHTTPRequestOperationManager 和其他 NSURLConnection 相关类在 AFNetworking 3.x 中不可用。

关于swift - 无法在 Today Extension 上使用 AFNetworking,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34674354/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com