facebook / facebook-ios-sdk

Used to integrate the Facebook Platform with your iOS & tvOS apps.
https://developers.facebook.com/docs/ios
Other
7.79k stars 3.55k forks source link

Difficulty compiling 15.1.0 from objective-c code #2140

Open mikehardy opened 1 year ago

mikehardy commented 1 year ago

Checklist before submitting a bug report

Xcode version

14.0

Facebook iOS SDK version

15.1.0

Dependency Manager

CocoaPods

SDK Framework

Core

Goals

I am the maintainer of react-native-fbsdk-next (the current FBSDK wrapper, we drive a lot of SDK usage :smile: - 64,000+ package downloads a week it appears https://www.npmjs.com/package/react-native-fbsdk-next )

I am trying to update our wrapper to use facebook-ios-sdk 15.1.0, it worked with 15.0.0

We are still written in Objective-C, and need swift/objc interop to work well

Currently we advise people that do deep-linking to import the module in AppDelegate.mm like so:

import <FBSDKCoreKit/FBSDKCoreKit-swift.h>

I understand from other issues that @import FBSDKCoreKit; is the recommended objc interop way of doing it but:

1) believe it or not this worked great with v15.0.0 of the SDK here 2) if we do that we get warnings about c++ modules not being in use, because of the way react-native compiles things

(same as noted in following comments on that issue linked just above: https://github.com/facebook/facebook-ios-sdk/issues/2043#issuecomment-1122049872)

So the goal is just to get the react-native-fbsdk-next obj-c code compiling correctly vs v15.1.0 here in a react-native-compatible way

Expected results

A successful compile

Actual results


❌ /Users/mike/Library/Developer/Xcode/DerivedData/RNFBSDKExample-fyfqqrwanmaihzdzdblaijkftntu/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FBSDKCoreKit/FBSDKCoreKit.framework/Headers/FBSDKCoreKit-swift.h:2430:146: cannot find protocol declaration for 'SFSafariViewControllerDelegate'
@interface _BridgeAPI : NSObject <FBSDKBridgeAPIRequestOpening, FBSDKApplicationObserving, FBSDKURLOpener, FBSDKContainerViewControllerDelegate, SFSafariViewControllerDelegate>
                                                                                                                                                 ^
❌ /Users/mike/Library/Developer/Xcode/DerivedData/RNFBSDKExample-fyfqqrwanmaihzdzdblaijkftntu/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FBSDKCoreKit/FBSDKCoreKit.framework/Headers/FBSDKCoreKit-swift.h:2445:56: cannot find protocol declaration for 'ASWebAuthenticationPresentationContextProviding'
@interface _BridgeAPI (SWIFT_EXTENSION(FBSDKCoreKit)) <ASWebAuthenticationPresentationContextProviding>
                                                       ^
❌ /Users/mike/Library/Developer/Xcode/DerivedData/RNFBSDKExample-fyfqqrwanmaihzdzdblaijkftntu/Build/Products/Debug-iphonesimulator/XCFrameworkIntermediates/FBSDKCoreKit/FBSDKCoreKit.framework/Headers/FBSDKCoreKit-swift.h:2446:4: expected a type
- (ASPresentationAnchor _Nonnull)presentationAnchorForWebAuthenticationSession:(ASWebAuthenticationSession * _Nonnull)session SWIFT_WARN_UNUSED_RESULT;

Steps to reproduce

I think the best way to reproduce might be to try the PR I have open in our example app, I am not 100% of the best way to do it, but I think this might work:

That should reproduce the errors above.

RNFBSDKExample/ios/AppDelegate.mm has the integration with import. If you change it to swift @import style you get the c++ modules issue.

Perhaps there is a way to add an @obj protocol interop specifier or similar in FBSDKCoreKit? Perhaps there is something I/we could put in our podspec that would help?

It is possible to play with possibilities by reaching directly in to RNFBSDKExample/node_modules/react-native-fbsdk-next and altering things (like perhaps the podspec to add compiler flags)

I wish I had more Obj-C/Swift interop experience but hopefully, since we (me, really at this point) are now maintaining the facebook module for react-native after it was pulled out of the main facebook/meta repos you will take pity on my and help keep it going, I would certainly appreciate it

Code samples & details

https://github.com/thebergamo/react-native-fbsdk-next/blob/master/RNFBSDKExample/ios/RNFBSDKExample/AppDelegate.mm
TarasOsiris commented 1 year ago

I am experiencing the same issue when trying to make this SDK work with UE, did you find any solutions to this problem?

mikehardy commented 1 year ago

No, I did not find a workaround, I'm stuck at 15.0.0. No response yet from maintainer(s) - though I see a commit from @samodom on Nov 8 and this was logged on Nov 2. Sam, I am not implying any expectation of response time with that comment, just saying as a general statement "the repository seems alive, Sam was here after the issue, perhaps it will get attention eventually" :-). Cheers

TarasOsiris commented 1 year ago

I have actually found the solution, you should add respective imports to the files that yield errors. On 16 Dec 2022, 19:39 +0200, Mike Hardy @.***>, wrote:

No, I did not find a workaround, I'm stuck at 15.0.0. No response yet from maintainer(s) - though I see a commit from @samodom on Nov 8 and this was logged on Nov 2. Sam, I am not implying any expectation of response time with that comment, just saying as a general statement "the repository seems alive, Sam was here after the issue, perhaps it will get attention eventually" :-). Cheers — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

mikehardy commented 1 year ago

@TarasOsiris can you be more specific, perhaps with an example or a diff or similar? I feel like I tried most things, but I must be unaware of the exact technique you mention as it did not occur to me and I'm not sure exactly what you mean. Thanks in advance if you can

xtealer commented 1 year ago

Hello, I've had this issue and spent couple hours debugging as well... Just figured out that AppDelegate extension ended in .mm and that stands for Objective C++ which does not support the imports that are producing these warnings! Just rename to .m and rewrite any Objective C+ code to Objective C and it should work! :)

https://stackoverflow.com/questions/29142045/module-not-recognized-in-xcode-project

muhachev commented 1 year ago

You should consider adding the appropriate XCode frameworks to your build: SafariServices and AuthenticationServices. Then just import them: #import <AuthenticationServices/AuthenticationServices.h> #import <SafariServices/SafariServices.h>

SufianBabri commented 10 months ago

Just remember to put the import statements (shared by @muhachev) before the #import <FBSDKCoreKit/FBSDKCoreKit-swift.h>.

Big thanks to this comment.