React-native-fbsdk: Question - Clicking Cancel button in modal causing app crashed | iOS

Created on 4 Feb 2019  路  14Comments  路  Source: facebook/react-native-fbsdk

Hi! I have a question, How to handle on cancel request by user in login modal?

screen shot 2019-02-04 at 12 53 11

My code to call the login function

_loginFB = async () => {
    let result
    try {
      result = await LoginManager.logInWithReadPermissions(['public_profile', 'email'])
    } catch (nativeError) {
      console.log('nativeError', nativeError)
      try {
        result = await LoginManager.logInWithReadPermissions(['public_profile', 'email'])
      } catch (webError) {
        console.log('webError', webError)
      }
    }
    if (result.isCancelled) {
      Alert.alert('Error', 'Login Failed, please check your Facebook email setting', [
        {
          text: 'OK'
        }
      ])
    } else {
      console.log('FB RESULT ===', result)
      this._FBGraphRequest('id,name,email,first_name,last_name', this._FBLoginCallback)
    }
  }

My app is crashed after clicking the button. Here is the stack trace

2019-02-04 12:55:06.050452+0800 ***********[51137:539322] +[NSError fbErrorFromReturnURLParameters:]: unrecognized selector sent to class 0x10e41b338
2019-02-04 12:55:06.073173+0800 ***********[51137:539322] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSError fbErrorFromReturnURLParameters:]: unrecognized selector sent to class 0x10e41b338'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001119911bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x00000001102f3735 objc_exception_throw + 48
    2   CoreFoundation                      0x00000001119afe44 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x0000000111995ed6 ___forwarding___ + 1446
    4   CoreFoundation                      0x0000000111997da8 _CF_forwarding_prep_0 + 120
    5   ***********                           0x000000010c8c5454 -[FBSDKLoginURLCompleter setErrorWithDictionary:] + 146
    6   ***********                           0x000000010c8c445d -[FBSDKLoginURLCompleter initWithURLParameters:appID:] + 335
    7   ***********                           0x000000010c8c9642 -[FBSDKLoginManager(Native) application:openURL:sourceApplication:annotation:] + 240
    8   ***********                           0x000000010c36d60a __77-[FBSDKApplicationDelegate application:openURL:sourceApplication:annotation:]_block_invoke + 90
    9   ********                           0x000000010c36d430 -[FBSDKApplicationDelegate application:openURL:sourceApplication:annotation:] + 880
    10  ********                           0x000000010c36fa43 __68-[FBSDKApplicationDelegate _setSessionCompletionHandlerFromHandler:]_block_invoke + 291
    11  AuthenticationServices              0x000000011976786e __78-[ASWebAuthenticationSession initWithURL:callbackURLScheme:completionHandler:]_block_invoke + 136
    12  SafariServices                      0x000000010e69d661 -[SFAuthenticationSession safariViewController:hostApplicationOpenURL:] + 128
    13  SafariServices                      0x000000010e6d86fb -[SFAuthenticationViewController remoteViewController:hostApplicationOpenURL:] + 105
    14  SafariServices                      0x000000010e706062 -[SFBrowserRemoteViewController willOpenURLInHostApplication:] + 68
    15  CoreFoundation                      0x000000011199803c __invoking___ + 140
    16  CoreFoundation                      0x00000001119954d5 -[NSInvocation invoke] + 325
    17  libdispatch.dylib                   0x00000001137f3602 _dispatch_client_callout + 8
    18  libdispatch.dylib                   0x00000001137f6b78 _dispatch_block_invoke_direct + 301
    19  FrontBoardServices                  0x0000000119217ba8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    20  FrontBoardServices                  0x0000000119217860 -[FBSSerialQueue _performNext] + 457
    21  FrontBoardServices                  0x0000000119217e40 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    22  CoreFoundation                      0x00000001118f6721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    23  CoreFoundation                      0x00000001118f5f93 __CFRunLoopDoSources0 + 243
    24  CoreFoundation                      0x00000001118f063f __CFRunLoopRun + 1263
    25  CoreFoundation                      0x00000001118efe11 CFRunLoopRunSpecific + 625
    26  GraphicsServices                    0x0000000115fc21dd GSEventRunModal + 62
    27  UIKitCore                           0x000000011f69581d UIApplicationMain + 140
    28  ***********                           0x000000010c344bdd main + 1037
    29  libdyld.dylib                       0x0000000113869575 start + 1
    30  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

react-native-fbsdk: "^0.8.0"
facebook SDK: unknown (copied from my colleague, using newest SDK causing Include of non-modular header inside framework module error)

Most helpful comment

I change fb framework LoginKit to CoreKit and it's work like a charm.
-force_load
${PROJECT_DIR}/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit

Thanks

All 14 comments

Hi,Maybe you need to add '-ObjC' to Other Linker Flags.

I'm also having the exact issue with "react-native-fbsdk": "^0.8.0". And I already have -ObjC in my other linker flags.

+[NSError fbErrorFromReturnURLParameters:]: unrecognized selector sent to class 0x109cf4338
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSError fbErrorFromReturnURLParameters:]: unrecognized selector sent to class 0x109cf4338'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010ce761bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x000000010af60735 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010ce94e44 +[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x000000010ce7aed6 ___forwarding___ + 1446
    4   CoreFoundation                      0x000000010ce7cda8 _CF_forwarding_prep_0 + 120
    5   MyApp                               0x0000000108ef9b2b -[FBSDKLoginURLCompleter setErrorWithDictionary:] + 146
    6   MyApp                               0x0000000108ef7a22 -[FBSDKLoginURLCompleter initWithURLParameters:appID:] + 335
    7   MyApp                               0x0000000108f01326 -[FBSDKLoginManager(Native) application:openURL:sourceApplication:annotation:] + 240
    8   MyApp                               0x0000000108f20a35 __77-[FBSDKApplicationDelegate application:openURL:sourceApplication:annotation:]_block_invoke + 71
    9   MyApp                               0x0000000108f2079b -[FBSDKApplicationDelegate application:openURL:sourceApplication:annotation:] + 511
    10  MyApp                               0x0000000108f225a9 __68-[FBSDKApplicationDelegate _setSessionCompletionHandlerFromHandler:]_block_invoke + 167
    11  AuthenticationServices              0x0000000124ec886e __78-[ASWebAuthenticationSession initWithURL:callbackURLScheme:completionHandler:]_block_invoke + 136
    12  SafariServices                      0x000000010f22e661 -[SFAuthenticationSession safariViewController:hostApplicationOpenURL:] + 128
    13  SafariServices                      0x000000010f2696fb -[SFAuthenticationViewController remoteViewController:hostApplicationOpenURL:] + 105
    14  SafariServices                      0x000000010f297062 -[SFBrowserRemoteViewController willOpenURLInHostApplication:] + 68
    15  CoreFoundation                      0x000000010ce7d03c __invoking___ + 140
    16  CoreFoundation                      0x000000010ce7a4d5 -[NSInvocation invoke] + 325
    17  libdispatch.dylib                   0x000000010ff8b54b _dispatch_client_callout + 8
    18  libdispatch.dylib                   0x000000010ff8e60b _dispatch_block_invoke_direct + 312
    19  FrontBoardServices                  0x000000011698bba8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
    20  FrontBoardServices                  0x000000011698b860 -[FBSSerialQueue _performNext] + 457
    21  FrontBoardServices                  0x000000011698be40 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
    22  CoreFoundation                      0x000000010cddb721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    23  CoreFoundation                      0x000000010cddaf93 __CFRunLoopDoSources0 + 243
    24  CoreFoundation                      0x000000010cdd563f __CFRunLoopRun + 1263
    25  CoreFoundation                      0x000000010cdd4e11 CFRunLoopRunSpecific + 625
    26  GraphicsServices                    0x00000001124801dd GSEventRunModal + 62
    27  UIKitCore                           0x0000000117a1f81d UIApplicationMain + 140
    28  MyApp                               0x0000000108c74cab main + 80
    29  libdyld.dylib                       0x000000010fffb575 start + 1
    30  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException

I also currently have this issue. This was shown in my stack trace

[NSError fbErrorFromReturnURLParameters:]
:unrecognized selector sent to class 0x10fc18338

*** Terminating app due to uncaught exception
'NSInvalidArgumentException',
reason: '+[NSError fbErrorFromReturnURLParameters:]
: unrecognized selector sent to class 0x10fc18338'

So I did some digging for fbErrorFromReturnURLParameters and noticed some things that I hope give some insight into why this might be happening

  1. fbErrorFromReturnURLParameters isn't recognized as a selector because it isn't defined anywhere that RCTFBSDK has reference to so it makes sense that it can't find it
  2. The objective c facebook sdk does however have this defined in
    FBSDKLoginKit/FBSDKLoginKit/Internal/FBSDKLoginError.m
    See this link for the definition fbErrorFromReturnURLParameters
  3. This is listed as one of the possible errors in FBSDKLoginError.h
@interface NSError (FBSDKLoginError)

+ (NSError *)fbErrorForFailedLoginWithCode:(FBSDKLoginError)code;
+ (NSError *)fbErrorForSystemAccountStoreError:(NSError *)accountStoreError;
+ (NSError *)fbErrorForSystemPasswordChange:(NSError *)innerError;

+ (nullable NSError *)fbErrorFromReturnURLParameters:(NSDictionary<NSString *, id> *)parameters;
+ (nullable NSError *)fbErrorFromServerError:(NSError *)serverError;

@end

I hope this helps isolate the issue a bit while addressing this. If there's any more information I can give to help out please let me know. I'll comment if I find anything in the meantime

The '-ObjC' to Other Linker Flags worked for me (added for the main project).
Alternatively you can try to force load each of the SDK's Frameworks.

-ObjC is already in my Other Linker Flags. What version are you using, @georgii11? I think the issue is related to fbErrorFromReturnURLParameters, as @NoHurryNoPause outlines.

@spencer-evans-pnt I am using FacebookSDKs-iOS-4.39.1.
The crash was indeed caused by a fb error which didn't have a definition because it was not loaded because of some automatic optimization that causes skipping loading some objects. Normally that optimization can be avoided by using the the -objc or -force_load flags.
Don't know why -objc is not working for you, maybe it has something to do with how you are building or generating projects... I know someone else who had this issue (and, unlike me, was building using xamarin) and objc didn't work for them, but force loading did... no idea why though...

@georgii11 great point on using force_loading. I appreciate the help! 馃檶

Adding the following to Other Linker Flags fixed it:
-force_load
${PROJECT_DIR}/Frameworks/FBSDKLoginKit.framework/FBSDKLoginKit

Note: the path may be different depending on where your FBSDKLoginKit.framework is located

I try it but it's not working for me. App is crash on start using mobile data .
@georgii11 @NoHurryNoPause any help !

I change fb framework LoginKit to CoreKit and it's work like a charm.
-force_load
${PROJECT_DIR}/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit

Thanks

I had the same issue where the application crashed on cellular data - would work fine on wifi
The error I was getting was

NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x1b41d0560
default 11:21:00.937037 -0400 name_of_app * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[NSError fbErrorWithCode:userInfo:message:underlyingError:]: unrecognized selector sent to class 0x1b41d0560'

I had previously added -ObjC in Other linker settings but that wasn't cutting it.
adding the following to Other Linker Flags worked
-force_load
${PROJECT_DIR}/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit

Just if anyone found it a bit unclear, the is what worked for me:

  • Open Xcode and click on the main project (using the targets didn't work)
  • in "Build Settings" search "other linker flags"
  • Add the entries in the screenshot
  • Adding just "-ObjC" was not enough, I had to add the link to the frameworks too as indicated above. For security, I added both the CoreKit and LoginKit (adding just CoreKit) wasn't enough to fix the bug

Screenshot 2019-06-24 at 10 36 58

It seems like the order of your Framework search paths also makes a difference.

(In xCode Build Settings --> Framework Search Paths)

For me, this worked:

Screen Shot 2019-07-11 at 8 33 35 AM

and this did not:

Screen Shot 2019-07-11 at 8 34 08 AM

Note the order of $(PROJECT_DIR) vs. the other two SDKs I am using.

I need to -force_load both FBSDKCoreKit.framework/FBSDKCoreKit and FBSDKLoginKit.framework/FBSDKLoginKit

Just add

LoginManager.logOut();

before

LoginManager.logInWithReadPermissions etc.

fixed for me.

Was this page helpful?
0 / 5 - 0 ratings