Can I build my own networking framework (which is dependent on AFNetworking) as a watchOS2 framework?

爱⌒轻易说出口 提交于 2019-11-28 23:46:43

According to the AFNetworking documentation:

URL Loading The most commonly used classes in the URL loading system allow your app to retrieve the content of a URL from the source. You can retrieve that content in many ways, depending on your app’s requirements. The API you choose depends on the version of OS X or iOS your app targets and whether you wish to obtain the data as a file or an 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.

If you take a look at the diagrams on that page, it indicates that AFNetworking actually uses NSURLSession in some cases. However, since the SystemConfiguration framework is not available in watchkit, you would need to remove that dependency in order to include AFNetworking in both your iOS and watchkit apps.

I'm not sure what AFNetworking uses this framework for (it is probably very important!), but if there are certain files that wouldn't need these settings in the watch app you could modify the AFNetworking source code to not include those items on the watch app:

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

Here is a recent commit on github for AFNetworking to support watchOS.

Looking at the changelog..

Version 2.6.0 supports watchOS...

This release now supports watchOS 2.0, which relys on target conditionals that are only present in Xcode 7 and iOS 9/watchOS 2.0/OS X 10.10. If you install the library using CocoaPods, AFNetworking will define these target conditionals for on older platforms, allowing your code to complile. If you do not use Cocoapods, you will need to add the following code your to PCH file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!