I'm getting compiler warnings with AFNetworking, but shouldn't be. How do I fix it?
Solution 1
I'm not sure if you're using CocoaPods or not but this is a known issue being tracked on the AFNetworking Github page.
I was able to fix this by adding the correct import statements directly to my `PROJECTNAME-Prefix.pch there I changed it to this.
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#endif
If you have something else in there don't delete it. Just add the imports for SystemConfiguration and MobileCoreServices.
For OS X:
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <CoreServices/CoreServices.h>
#endif
Solution 2
If you're using swift: Xcode compiles Swift code before the Prefix.pch
file is compiled, so you'll get these warnings even if the correct imports are in your .pch file. The best solution I've found is to add them to the project's Bridging-Header.h
file before importing AFNetworking:
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import "AFNetworking.h"
Solution 3
This has already been answered, but still, if you're developing a command line tool potentially to be compiled for both OS X and iOS (not App Store for sure), you can add this:
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>
#if TARGET_OS_IPHONE
#import <MobileCoreServices/MobileCoreServices.h>
#elif TARGET_OS_MAC
#import <CoreServices/CoreServices.h>
#endif
#endif
By evaluating the target you're compiling to, it will include the proper files.
ageektrapped
Jason is an amazing developer-slash-genius. He currently specializes in designing and developing apps for iOS, with over 15 years mastering the craft of app development. He enjoys video games, barbecue, Negroni cocktails, and writing about himself in the third person.
Updated on July 31, 2022Comments
-
ageektrapped almost 2 years
I'm using the most excellent
AFNetworking
library in a project that I'm currently upgrading to iOS 6. I'm in the middle of the upgrade, whittling down the bunch of warnings that I get when compiling against the iOS 6 SDK.AFNetworking gives me two warnings in all targets:
SystemConfiguration framework not found in project, or not included in precompiled header. Network reachability functionality will not be available.
and
MobileCoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.
Here's the thing, though: those two
libraries
are added in all mytargets
. I'd like to get rid of those warnings the proper way; I won't modify theAFNetworking
files. I suspect it's Xcode being silly. It's admittedly a small thing, but leaving warnings around is bad practice.How can I remove those warnings?
I've tried restarting Xcode and cleaning. Both don't work.
-
ageektrapped over 11 yearsI'm not using CocoaPods, just a straight clone from github. I added MobileCoreServices and SystemConfiguration for other libraries, so didn't have to add them for AFNetworking.
-
Keith Smiley over 11 yearsAdding the import statements I posted to your .pch file in the Supporting Files group in your Xcode project should work. I just verified this fixing the warnings in a blank project.
-
Tomasz Szulc about 11 yearsThank you for this. Sometimes when warning are still in Issue Navigator you have to remove derived data for current project in '~/Library/Xcode/Developer/DerivedData'. Then clean and build. Should works correctly.
-
Bilbo Baggins about 11 yearsI several 'PARSE ISSUES' and 'SEMANTIC ISSUES' if I add it there. However if I add it to the AFHTTPClient.h then those errors disappear.
-
xMythicx almost 11 yearsYes the only way I was able to get the warnings to disappear was to do what Pritesh Desai said and add the two frameworks to the top of AFHTTPClient.h
-
horseshoe7 almost 11 yearsI am using CocoaPods, so this solution with the .pch won't work because the library has already been compiled. Any other solutions?
-
Keith Smiley almost 11 years@horseshoe7 this should work fine with CocoaPods you need to put this in your own
.pch
file and it will silence the warnings when linking from the generated static library -
horseshoe7 almost 11 yearsbut the warning is in the pods project... oh wait, my bad. it's in the AFIncrementalStore pod target... thanks!
-
Besi about 9 years@KeithSmiley I find it important to note that this has to be before the import of
AFNetworking
itself. -
Max MacLeod almost 9 yearsThis worked for me. Key thing is to have the imports in both the PCH and the bridging header. Sequence is important so the imports must precede #import "AFNetworking.h"