2
votes

Hi I have just upgraded my app to iOS 9 and using Facebook's latest SDK (version 4.6) for facebook login.

I am using custom login button hence using the LoginManager class for the same. With the previous version it was working fine but now my app gets crashed whenever I press the login button saying "unrecognized selector sent to instance"

Below is the code I am using in my GameScene class to login.

var fbLogin = FBSDKLoginManager()
func onClickFBLogin(){
        let vc = self.view?.window?.rootViewController
        fbLogin.logInWithReadPermissions(["public_profile"] as [AnyObject], fromViewController: vc, handler: {(result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in
            if(error != nil){
                print("Facebook login error \(error)")
            } else if(result.isCancelled){
                print("Facebook login cancelled")
            } else{
                print("facebook login successful")
                if(self.isSaveMeButtonPressed){
                    print("facebook login successful")
                }
            }
        })
}

The app is crashing with below log on Xcode.

[FBSDKLoginManager logInWithReadPermissions:fromViewController:handler:]: unrecognized selector sent to instance 0x7f82e51251e0

Anyone facing the same issue? Or someone who can help me sort this issue?

Thanks in advance.

3
Did you already revise your permission type?. Try to remove the "]" character leaving the code as ["public_profile"].Lucas Brito
@LucasBrito Sorry about that. That was a typo made here only. In the code it is not there.Rohit Goyal
"[public_profile]", u may want to edit this question first--this is wrong and therefore misleadingJunchao Gu
@JunchaoGu I did actually. It just reflected now. :/ Sorry about that.Rohit Goyal

3 Answers

1
votes

There was an issue in updating the Facebook SDK. It seems like Facebook has changed the way it used to install the SDK in Documents folder by giving a package file but now it gives an zip file which is not installable. Hence I just replaced the existing file in my ~\Documents\FacebookSDK folder. After that it looks like Xcode took some part of update code and some still remained same.

I removed all the frameworks from my project and re-added the usual way we add a framework in Xcode. It is working fine now.

Facebook should update its documentation on how to update to newer SDK.

0
votes

For iOS 9 you have add more keys to the info.plist. This error can be related to this.

<key>NSAppTransportSecurity</key>
<dict>
  <key>NSExceptionDomains</key>
  <dict>
    <key>facebook.com</key>
    <dict>
      <key>NSIncludesSubdomains</key> <true/>        
      <key>NSExceptionRequiresForwardSecrecy</key> <false/>
    </dict>
    <key>fbcdn.net</key>
    <dict>
      <key>NSIncludesSubdomains</key> <true/>
      <key>NSExceptionRequiresForwardSecrecy</key>  <false/>
    </dict>
    <key>akamaihd.net</key>
    <dict>
      <key>NSIncludesSubdomains</key> <true/>
      <key>NSExceptionRequiresForwardSecrecy</key> <false/>
    </dict>
  </dict>
</dict>

Facebook getting started

0
votes

Another possible issue is a facebook Pod install from CocoaPod. remove the pod from the Podfile in you project, run pod install and you'll see the facebook pod removed from the project. I used the facebook SDK from their website and importing the framework manually (and using their instructions to complete the facebook SDK integration). Re-compile and run your app again...

This is the complete error I got:

Checklists[14748:612592] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[FBSDKLoginManager isAuthenticationURL:]: unrecognized selector sent to instance 0x6000002887f0'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010999212b __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x000000010a55bf41 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000109a13024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x0000000109914f78 ___forwarding___ + 1432
    4   CoreFoundation                      0x0000000109914958 _CF_forwarding_prep_0 + 120
    5   FBSDKCoreKit                        0x00000001096e58b3 -[FBSDKApplicationDelegate openURLWithSafariViewController:sender:fromViewController:handler:] + 355
    6   Checklists                          0x0000000108b513ed -[FBSDKLoginManager(Native) performBrowserLogInWithParameters:handler:] + 654
    7   Checklists                          0x0000000108b50450 -[FBSDKLoginManager logInWithBehavior:] + 483
    8   Checklists                          0x0000000108b50250 -[FBSDKLoginManager logInWithPermissions:handler:] + 312
    9   Checklists                          0x0000000108b4ecde -[FBSDKLoginManager logInWithReadPermissions:fromViewController:handler:] + 280
    10  Checklists                          0x0000000108b4b757 -[FBSDKLoginButton _buttonPressed:] + 1662
    11  UIKit                               0x000000010b504972 -[UIApplication sendAction:to:from:forEvent:] + 83
    12  UIKit                               0x000000010b683c3c -[UIControl sendAction:to:forEvent:] + 67
    13  UIKit                               0x000000010b683f59 -[UIControl _sendActionsForEvents:withEvent:] + 450
    14  UIKit                               0x000000010b682e86 -[UIControl touchesEnded:withEvent:] + 618
    15  UIKit                               0x000000010b57a807 -[UIWindow _sendTouchesForEvent:] + 2807
    16  UIKit                               0x000000010b57bf2a -[UIWindow sendEvent:] + 4124
    17  UIKit                               0x000000010b51f365 -[UIApplication sendEvent:] + 352
    18  UIKit                               0x000000010be6ba1d __dispatchPreprocessedEventFromEventQueue + 2809
    19  UIKit                               0x000000010be6e672 __handleEventQueueInternal + 5957
    20  CoreFoundation                      0x0000000109935101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    21  CoreFoundation                      0x00000001099d4f71 __CFRunLoopDoSource0 + 81
    22  CoreFoundation                      0x0000000109919a19 __CFRunLoopDoSources0 + 185
    23  CoreFoundation                      0x0000000109918fff __CFRunLoopRun + 1279
    24  CoreFoundation                      0x0000000109918889 CFRunLoopRunSpecific + 409
    25  GraphicsServices                    0x0000000110ae99c6 GSEventRunModal + 62
    26  UIKit                               0x000000010b5035d6 UIApplicationMain + 159
    27  Checklists                          0x0000000108b49747 main + 55
    28  libdyld.dylib                       0x000000010e45dd81 start + 1
    29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException