I am unable to use AFNetworking library in my app extension due to that was trying to access the UIApplication class methods. Does any one knows here any other better network library that does not access UIApplication class?. Please suggest.

- 2,056
- 2
- 23
- 34
2 Answers
quote from Guard for unsupported features of iOS 8 extensions #2589
To fix this issue i had to put AF_APP_EXTENSIONS=1 as a preprocessor macro for the Pods-hitta.se WatchKit Extension-AFNetworking target. Adding #define AF_APP_EXTENSIONS to the prefix header didn't work, neither did adding it as a preprocessor macro to the watch extension target work.
So click on Pods project in Project Navigator, then select Pods-{your-app-name-extension}-AFNetworking. Next go to Build Settings and find Preproccessor Macros where you add new line with "AF_APP_EXTENSIONS=1"
Also wrap it with +#if !defined(AF_APP_EXTENSIONS) at beginning. And end it +#endif
full example of wrapping:
- (void)updateNetworkActivityIndicatorVisibility {
+#if !defined(AF_APP_EXTENSIONS)
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:[self isNetworkActivityIndicatorVisible]];
+#endif
}

- 808
- 8
- 21
You can use AFNetworking with extension. You just need follow the instruction below.
When using AFNetworking in an App Extension, #define AF_APP_EXTENSIONS to avoid using unavailable APIs.

- 2,014
- 13
- 14
-
1Where do you place the macro?? – d2burke Nov 18 '14 at 05:49
-
This answer make no sense. Where to define this macro? How to use this macro? And how to import AFNetworking.h? – Valentin Shamardin Jan 08 '15 at 16:22