在使用Apple Watch运行App时,需要在watchOS扩展程序中安装Alamofire库。如果Alamofire未正确安装,则会导致https请求的编写失败。可以按照以下步骤来解决该问题:
pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => '5.4.0'
import Alamofire
let url = "https://example.com"
AF.request(url).responseJSON { response in
debugPrint(response)
}
注意:确保在info.plist文件中设置应用的App Transport Security设置,以允许https请求。