Home > Mobile >  Is it feasible to integrate Facebook SDK 15.x with iOS using Objective C
Is it feasible to integrate Facebook SDK 15.x with iOS using Objective C

Time:12-07

We were able to test the FB iOS SDK 11.x which had the Objective-C interfaces, but would it be possible to do the same with FB iOS SDK 15.x since it seems to contain only Swift interfaces

We were able to test the FB iOS SDK 11.x which had the Objective-C interfaces, but would it be possible to do the same with FB iOS SDK 15.x

CodePudding user response:

While it is technically possible, the minimum target version of the Facebook iOS SDK raised from iOS 9 in v11 to iOS 12 in v15. You might want to ensure your minimum targeted version matches.

Also, a number of types have been converted from Objective-C to Swift since v13. As a consequence, developers may need to use modular import statements when using certain Facebook SDK modules in order to avoid encountering compilation errors in Objective-C.

// When importing a framework in this form:
#import <FBSDKShareKit/FBSDKShareKit.h>

// You may be need to update to this form when unknown symbol warnings appear:
@import FBSDKShareKit;

Source - https://github.com/facebook/facebook-ios-sdk/blob/main/CHANGELOG.md#swift-conversions

Essentially, Swift sources that you use inside your Objective-C implementations will be accessed through generated headers called "bridging" headers. For example, when properly configured, FBSDKCoreKit generates a FBSDKCoreKit-Swift.h which lets you access the Swift implementations. Note that this bridging header is automatically used when the module is referenced by a modular import directive, for example @import FBSDKCoreKit. This is the way to go if you're using Cocoapods.

Otherwise, if you want to build and reference the module manually, the Swift documentation provides guidance about what you're trying to achieve :

To import a set of Swift files in the same framework target as your Objective-C code, import the Xcode-generated header for your Swift code into any Objective-C .m file where you want to use your Swift code.

Because the generated header is part of the framework’s public interface, only declarations marked with the public or open modifier appear in the generated header for a framework target. Methods and properties that are marked with the internal modifier and declared within a class that inherits from an Objective-C class are accessible to the Objective-C runtime. However, they’re inaccessible at compile time and don’t appear in the generated header for a framework target.

Import Swift code into Objective-C within the same framework:

  1. Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes.
  2. Import the Swift code from that framework target into any Objective-C .m file within that target using this syntax and substituting the appropriate names:
  3. Import using the Bridging header #import <ProductName/ProductModuleName-Swift.h>

Source - https://developer.apple.com/documentation/swift/importing-swift-into-objective-c

CodePudding user response:

We were able to test the FB iOS SDK 11.x which had the Objective-C interfaces, but would it be possible to do the same with FB iOS SDK 15.x since it seems to contain only Swift interfaces

We were able to test the FB iOS SDK 11.x which had the Objective-C interfaces, but would it be possible to do the same with FB iOS SDK 15.x

  • Related