gpt4 book ai didi

ios - 我可以构建自己的网络框架(依赖于 AFNetworking)作为 watchOS2 框架吗?

转载 作者:可可西里 更新时间:2023-11-01 03:00:41 27 4
gpt4 key购买 nike

我一直在尝试修改我的项目以支持 WatchOS2 架构。目前我有一个基于 AFNetworking 的网络框架。到目前为止,我一直在用我的 watch 应用程序使用它。现在我正在尝试为 watchos/watchsimulator 平台构建框架。

我得到的是 找不到“SystemConfiguration/SystemConfiguration.h”文件某些 AFNetworking 类的错误。

我知道系统配置不是 watchOS2 可用的系统框架之一。和网络苹果says :

网络

对基于网络的操作的支持包括以下技术:

WatchKit 扩展可以使用 NSURLSession 对象直接访问网络。 WatchKit 扩展可以完全访问 NSURLSession 功能,包括在后台下载文件的能力。有关如何使用此类的信息,请参阅 URL 加载系统编程指南。Watch Connectivity 框架支持 Watch 应用程序和 iOS 应用程序之间的双向通信。使用此框架来协调两个应用程序之间的事件。有关详细信息,请参阅与您的配套 iOS 应用程序通信。

我想为我的网络 sdk 同时支持 iOS 和 watchos。有没有办法让这个项目为 watchOS 平台构建?或者这是否意味着我只能在 watch 应用程序中使用 NSURLConnection?

最佳答案

根据AFNetworking documentation :

URL Loading The most commonly used classes in the URL loading systemallow your app to retrieve the content of a URL from the source. Youcan retrieve that content in many ways, depending on your app’srequirements. The API you choose depends on the version of OS X or iOSyour app targets and whether you wish to obtain the data as a file oran in-memory block of data:

  • In iOS 7 and later or OS X v10.9 and later, NSURLSession is the preferred API for new code that performs URL requests.

如果您查看该页面上的图表,它表明 AFNetworking 在某些情况下实际上使用 NSURLSession。但是,由于 SystemConfiguration 框架在 watchkit 中不可用,您需要删除该依赖项才能在您的 iOS 和 watchkit 应用程序中包含 AFNetworking。

我不确定 AFNetworking 使用此框架的目的是什么(它可能非常重要!),但是如果 watch 应用程序中有某些文件不需要这些设置,您可以修改 AFNetworking 源代码以使其不包含 watch 应用程序上的那些项目:

#if os(iOS)
// Include SystemConfiguration framework
#elseif os(watchOS)
// Exclude SystemConfiguration framework
#endif

关于ios - 我可以构建自己的网络框架(依赖于 AFNetworking)作为 watchOS2 框架吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31324001/

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