Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

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

I've been trying to modify my project to support WatchOS2 architecture. Currently I have a networking framework that is based on AFNetworking. I've been using it with my watch app so far. Now I'm trying to build the framework for watchos/watchsimulator platforms.

What I'm getting is 'SystemConfiguration/SystemConfiguration.h' file not found error for some AFNetworking classes.

I know that system configuration is not one of the available system frameworks for watchOS2. And for networking apple says:

Networking

Support for network-based operations includes the following technologies:

WatchKit extensions can access the network directly using an NSURLSession object. WatchKit extensions have full access to the NSURLSession capabilities, including the ability to download files in the background. For information on how to use this class, see URL Loading System Programming Guide. The Watch Connectivity framework supports bidirectional communication between your Watch app and iOS app. Use this framework to coordinate activities between the two apps. For more information, see Communicating with Your Companion iOS App.

I want to support both iOS and watchos for my networking sdk. Is there a way to make this project built for watchOS platform? Or is that mean I am only allowed to use NSURLConnection inside my watch app?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...