I have to implement a Facebook sharing method... I watched the video, read a couple of tutors, etc...
1: I registered my app, downloaded the sdk, the samples are running fine
2: when i drag and drop the FacebookSDK.framework into my app (not a new app, it has custom frameworks), and include the #import into the desired class and the appdelegate, during the build, i keep getting the following error in FBRequest.h:
LLVM GCC 4.2 error
'#pragma' is not allowed here
LLVM GCC 4.2 error
instance variable '<unnamed>' has unknown size
LLVM GCC 4.2 error
expected `;' before 'NSError'
This is the problematic area
#interface FBRequest : NSObject {
#private
id<FBRequestDelegate> _delegate;
NSString* _url;
NSURLConnection* _connection;
NSMutableData* _responseText;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
FBRequestState _state;
#pragma GCC diagnostic pop
NSError* _error;
BOOL _sessionDidExpire;
id<FBGraphObject> _graphObject;
}
XCode 4.5, trying to run in ios 5.1 simulator and ios6 iPod 4. gen
Thanks
try switching to Apple LLVM compiler 4.1 instead of LLVM GCC 4.2 in your Project > Build Settings > Build Options > Compiler for C/C++/Objective-C
p.s. Choose "All" if you don't see "Compiler for C/C++/Objective-C" there.
Related
I have a local pod which mocks a bluetooth device. In it there is this line...
CBATTRequest *request = [CBATTRequest new];
Since upgrading xcode, the build errors out saying 'new' is unavailable. Clicking through confirms that in the ios 14.5 SDK, this method (init actually) is indeed marked "unavailable"
/*!
* #class CBATTRequest
*
* #discussion Represents a read or write request from a central.
*
*/
NS_CLASS_AVAILABLE(10_9, 6_0)
CB_EXTERN_CLASS #interface CBATTRequest : NSObject
- (instancetype)init NS_UNAVAILABLE;
...the thing is though, my simulator is set to ios 12.4 and the pods deployment target is set to 12.0.
As stated, this was compiling before I upgraded xcode. The pod dev subteam says it works on ios <= 12.4.
So why is it now compiling against 14.5 rather than 12.x? How do I get it to compile against 12.x?
In Xcode 12.5 init NS_UNAVAILABLE makes automatically unavailable new.
I don't know how it was working correctly with actually unavailable initializer, but now you had to find correct way of retrieving reference to valid CBATTRequest object
How to suppress deprecation warning within availability macro? I know availability is a great way to check for new APIs but I am struggling how to suppress deprecation warnings. What alternatives do I have other than those mentioned below? (1.pragma 2.performSelector)
MyModel *model;
if (#available(macOS 10.13, *)) {
NSError *error;
model = [NSKeyedUnarchiver unarchivedObjectOfClass:[MyModel class] fromData:metadata error:&error];
if (error) {
[[NSAlert alertWithError:error] runModal];
}
} else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
model = [NSKeyedUnarchiver unarchiveObjectWithData:metadata];
#pragma clang diagnostic pop
}
Alternatively use to suppress warning
if ([NSKeyedUnarchiver respondsToSelector:#selector(unarchiveObjectWithData:)]) {
model = [NSKeyedUnarchiver performSelector:#selector(unarchiveObjectWithData:) withObject:metadata];
}
You will only get a deprecation warning if you are using an API that was deprecated at or earlier than your target's Deployment Target.
NSKeyedUnarchiver unarchiveObjectWithData is deprecated as of macOS 10.14. You will only get a deprecation warning if your target's Deployment Target is macOS 10.14 or later. But the code you posted implies you wish to support macOS 10.12 or earlier.
NSKeyedUnarchiver unarchivedObjectOfClass:fromData:error: was added in macOS 10.13.
If you really only want a Deployment Target of macOS 10.13 or later then you don't need the if (#available(macOS 10.13, *)) or the else. Just use the new API and be done.
The code in your question (minus the pragmas) should only be used if you want to support macOS 10.12 or earlier. Then your target's Deployment Target needs to be set to macOS 10.12 or earlier. And in this case you don't need the pragmas and you won't get any deprecation warnings.
So, i have some places where things are only available after a certain version. One example is some new NFC stuff i've introduced in my app:
#property(nonatomic, retain) NFCNDEFReaderSession *nfcSession;
I also have it in methods, where i get it even though i check for class availability, for example:
if ([NFCNDEFReaderSession class]){
my app works fine, but i get an xcode warning saying
NFCNDEFReaderSession is partial: introduced in iOS 11.0
I have looked around but haven't found a way to tell the compiler that it's fine and get rid of the warning.
Pointers much appreciated!
Add NS_AVAILABLE_IOS(11.0) to the end of the method name. For example:
- (BOOL)tableView:(UITableView *)tableView canHandleDropSession:(id<UIDropSession>)session NS_AVAILABLE_IOS(11.0) {
}
Method calls can be wrapped in the following to silence the new API warning
if (#available(iOS 11.0, *)) {}
You can silence specific warnings on parts of your code by adding Clang “pragmas” around it. In this case:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
// your code
#pragma clang diagnostic pop
Documentation: https://clang.llvm.org/docs/UsersManual.html#controlling-diagnostics-via-pragmas
To silence the warning, change the target's "Other warning flags" to either:
-Wno-partial-availability
-Wno-unguarded-availability
You can also turn off Unguarded availability in the project settings. If you're using Cocoapods, it's now on by default in the Pods project.
My company is developing an iOS SDK, which uses the new CallKit APIs. The SDK (.framework) is compiled with XCode 8 / SDK 10.0.
However, some of out customers are still using XCode 7 - When I try to integrate our SDK under a XCode 7 project, I got the following error :
ld: framework not found CallKit for architecture arm64
However, I put some macro directive into the SDK code, to provide a CoreTelephony fallback, but event with this trick, the project's target does not compile with the message above.
Here is the directive example :
#ifdef __IPHONE_10_0
#import CallKit;
#endif
Do you have a trick to use a SDK compiled with iOS 10 API working under XCode 7 ?
EDIT
Find a way to manage that. The idea is to lazy load CallKit (runtime). I had to call performSelector instead of calling directly methods.
Here is some code :
// Lazy load CallKit framework to keep compatibility for XCode 7 SDK integration
if ([[AppKit sharedInstance] systemVersion] >= kIosSystemVersion10) {
NSBundle *b = [NSBundle bundleWithPath:#"/System/Library/Frameworks/CallKit.framework"];
_isCallKitFrameworkLoaded = [b load];
}
if (_isCallKitFrameworkLoaded) {
SEL callObserverDelegate = NSSelectorFromString(#"setDelegate:queue:");
if ([_callObserver respondsToSelector:callObserverDelegate]) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[_callObserver performSelector:callObserverDelegate withObject:self withObject:(__bridge id)(_callObserverQueue)];
#pragma clang diagnostic pop
}
} else {
// CoreTelephony fallback
}
CallKit is available from iOS 10 and later. Xcode 7 support upto iOS 9 only. If you need to use this framework, you need to update to latest Xcode(obviously Xcode8) which supports iOS 10.
So users who are having iOS 10 only can use this feature and not iOS 9.
I recently upgraded the RevMob SDK of my cocos2d project, using Xcode 4.5. Below is a code to show what I have done:
#import <StoreKit/StoreKit.h>
#import <RevMobAds/RevMobAds.h>
- (void) applicationDidFinishLaunching:(UIApplication*)application{
[RevMobAds startSessionWithAppID:#"my app id"];
//some code here...
}
On running the project, on device or simulator, the app crashes with this error:
+[RevMobAds startSessionWithAppID:]: unrecognized selector sent to class
However, one thing which might be useful, is that when I added the RevMob framework to my Xcode, it gave me compilation errors (using LLVM GCC 4.2) for which I followed this answer.
This method was included in version 5.0.0 (RevMob changelog), so make sure that the framework that you are using is at least 5.0.0.