Q: App crashing when App is setting delegate of FirebaseMessaging My app try to use Firebase remote notification, I followed the Firebase guide. Now my app crashes in AppDelegate where I am trying to set the delegate of Firebase messaging. 
Here is the code 
[FIRApp configure];
[FIRMessaging messaging].delegate = self;

In the second line it crashes with crash message as given below:

+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]: unrecognized selector sent to class 0x10ef2a538
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason:
  '+[FIRInstanceIDCheckinPreferences preferencesFromKeychainContents:]:
  unrecognized selector sent to class 0x10ef2a538'
  * First throw call stack: (     0   CoreFoundation                      0x00000001116671e6 exceptionPreprocess + 294  1   libobjc.A.dylib
  0x0000000110cfc031 objc_exception_throw + 48  2   CoreFoundation
  0x00000001116e86c4 +[NSObject(NSObject) doesNotRecognizeSelector:] +
  132   3   CoreFoundation                      0x00000001115e9898
  ___forwarding_ + 1432   4   CoreFoundation                      0x00000001115e9278 _CF_forwarding_prep_0 + 120  5   MobilePro Dev
  0x000000010ed09af3 -[FIRInstanceIDCheckinStore
  cachedCheckinPreferences] + 407   6   MobilePro Dev
  0x000000010ed0d73a -[FIRInstanceIDStore resetCredentialsIfNeeded] +
  145   7   MobilePro Dev                       0x000000010ed0d230
  -[FIRInstanceIDStore initWithCheckinStore:tokenStore:delegate:] + 174     8   MobilePro Dev                       0x000000010ed0d154
  -[FIRInstanceIDStore initWithDelegate:] + 142     9   MobilePro Dev                       0x000000010ed10acc -[FIRInstanceIDTokenManager init] + 105  10 
  MobilePro Dev                       0x000000010ed022ae -[FIRInstanceID
  setupTokenManager] + 50   11  MobilePro Dev
  0x000000010ed0225c -[FIRInstanceID start] + 90    12  libdispatch.dylib 
  0x0000000114c4f7ec _dispatch_client_callout + 8   13  libdispatch.dylib
  0x0000000114c50d64 dispatch_once_f + 285  14  MobilePro Dev
  0x000000010ecfefac +[FIRInstanceID instanceID] + 45   15  MobilePro Dev
  0x000000010ed26a6a -[FIRMessaging initPrivately] + 38     16  MobilePro
  Dev                       0x000000010ed26939 25+[FIRMessaging
  messaging]_block_invoke + 41  17  libdispatch.dylib
  0x0000000114c4f7ec _dispatch_client_callout + 8   18  libdispatch.dylib
  0x0000000114c50d64 dispatch_once_f + 285  19  MobilePro Dev
  0x000000010ed2690d +[FIRMessaging messaging] + 45     20  MobilePro Dev
  0x000000010eaa9ac3 -[AppDelegate
  application:didFinishLaunchingWithOptions:] + 323     21  UIKit
  0x00000001128d96fb -[UIApplication
  _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 278  22  UIKit                               0x00000001128db172
  -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4123   23  UIKit                               0x00000001128e05cb
  -[UIApplication _runWithMainScene:transitionContext:completion:] + 1677   24  UIKit                               0x0000000112ca2f7e
  __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke
  + 866     25  UIKit                               0x0000000113075a39 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153    26  UIKit                               0x0000000112ca2bba
  -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236     27  UIKit                               0x0000000112ca33db
  -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 675  28  UIKit
  0x0000000113614614 __82-[_UIApplicationCanvas
  _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke
  + 299     29  UIKit                               0x00000001136144ae -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433     30  UIKit                               0x00000001132f875d
  __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke
  + 221     31  UIKit                               0x00000001134f34b7 _performActionsWithDelayForTransitionContext + 100   32  UIKit                               0x00000001132f8627 -[_UICanvasLifecycleSettingsDiffAction
  performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]
  + 223     33  UIKit                               0x00000001130750e0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392     34  UIKit                               0x00000001128deeac
  -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515     35 
  UIKit                               0x0000000112eb1bcb
  -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361   36 
  FrontBoardServices                  0x00000001176452f3 -[FBSSceneImpl
  _didCreateWithTransitionContext:completion:] + 331    37  FrontBoardServices                  0x000000011764dcfa
  __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 225     38 
  libdispatch.dylib                   0x0000000114c4f7ec
  _dispatch_client_callout + 8  39  libdispatch.dylib                   0x0000000114c54db8 _dispatch_block_invoke_direct + 592  40 
  FrontBoardServices                  0x0000000117679470
  __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24     41  FrontBoardServices                  0x000000011767912e
  -[FBSSerialQueue _performNext] + 439  42  FrontBoardServices                  0x000000011767968e -[FBSSerialQueue _performNextFromRunLoopSource] +
  45    43  CoreFoundation                      0x0000000111609bb1
  CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17   44  CoreFoundation                      0x00000001115ee4af
  __CFRunLoopDoSources0 + 271   45  CoreFoundation                      0x00000001115eda6f __CFRunLoopRun + 1263    46  CoreFoundation
  0x00000001115ed30b CFRunLoopRunSpecific + 635     47  GraphicsServices
  0x000000011779ca73 GSEventRunModal + 62   48  UIKit
  0x00000001128e2057 UIApplicationMain + 159    49  MobilePro Dev
  0x000000010eac56cf main + 111     50  libdyld.dylib
  0x0000000114ccc955 start + 1  51  ???
  0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with
  uncaught exception of type NSException


A: If you don't use pods, you must to add the objC linker flag for your target.
From the documentation:
"Integrate without CocoaPods
If you don't want to use Cocoapods, you can still take advantage of the Firebase SDKs by importing the frameworks directly.
Download the framework SDK zip. This is a ~1GB file and might take some time to download.
Unzip the file, then review the README for the Frameworks that you want to include in your app.
Add the ObjC linker flag in your Other Linker Settings in your target's build settings."
Link:
https://firebase.google.com/docs/ios/setup
https://developer.apple.com/library/archive/qa/qa1490/_index.html

A: When you call a delegate, you must ensure that all the required methods of that delegate are written.
Check the following method is called in your Appdelegate.
-(void)messaging:(FIRMessaging *)messaging didReceiveRegistrationToken:(NSString *)fcmToken 
{
}

Or ensure that FIRMessagingDelegate is written in your Appdelegate
@interface AppDelegate ()<FIRMessagingDelegate>


A: You need to change the Firebase configure method.
Call it as,
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 42.0), dispatch_get_main_queue(), ^{
       [FIRApp configure];
 });

It will solve your issue.

A: import FirebaseMessaging
FirebaseApp.configure()
Messaging.messaging().delegate = self


//MARK:- Messaging Delegate Method ..............................

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
            let token = Messaging.messaging().fcmToken
            print("FCM token: \(token ?? "")")
}

