gpt4 book ai didi

ios - 如何在 iOS Widget 中使用 Alamofire

转载 作者:搜寻专家 更新时间:2023-10-31 22:12:12 45 4
gpt4 key购买 nike

在我的 Widgets 目标中实现 Alamofire 时,它​​说例如“使用未解析的标识符‘Alamofire’。我需要以某种方式将我的 Widget 添加为 Alamofire 项目的目标。我该如何实现?

一些示例代码:

// Parameters
let parameters: [String : Any] = [
"id": id,
"state": true
]

Alamofire.request("https://someurl.com" method: .put, parameters: parameters, encoding: JSONEncoding.default).responseJSON { response in

// Check if the request was successful
if (response.result.isSuccess) {
let statusCode = response.response!.statusCode
if (statusCode == 200) {

} else {

}
}

}

最佳答案

我今天构建了一些扩展,这就是我安装 Alamofire 的方式。您的小部件是您工作区中的另一个项目,连同运行该小部件的主应用程序。因此,您需要在一个(或两个,取决于您的需要)中安装 Alamofire。将您的播客文件更改为:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '9.0'
use_frameworks!

target "MainAPP" do
pod 'Alamofire'
pod ‘SwiftyJSON’
end
target "Widget" do
pod 'Alamofire'
pod ‘SwiftyJSON’
end

编辑:如果您手动添加它,只需转到项目 -> 常规 -> 链接的框架和库,并将 Alamofire xcode 项目添加为依赖项

关于ios - 如何在 iOS Widget 中使用 Alamofire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42374587/

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