title: didRegisterForRemoteNotificationsWithDeviceToken not called after adding Firebase SDK. Swizzling disabled
body: <p>I'm trying to add Firebase SDK to my app. On Android side it's all good and works as expected. On iOS side it works that way I can make it receive messages via FCM, but cannot get APNs token at all. Sounds like easy problem/mistake?</p>
  
  <p>Firebase iOS SDK 5.17 and Firebase C++ SDK 5.5.0 are added and compiled in. I included following frameworks:</p>
  
  <pre><code>firebase.framework
  firebase_instance_id.framework
  firebase_messaging.framework
  FirebaseCore.framework
  FirebaseInstanceID.framework
  FirebaseMessaging.framework
  GoogleUtilities.framework
  Protobuf.framework
  </code></pre>
  
  <p>info.plist contains:</p>
  
  <pre><code>&lt;key&gt;FirebaseAppDelegateProxyEnabled&lt;/key&gt;
  &lt;false/&gt;
  </code></pre>
  
  <p>Yes, I need to disable method swizzling coz I need APNs token.</p>
  
  <p>Now in didRegisterForRemoteNotificationsWithDeviceToken:</p>
  
  <pre><code>- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
  [FIRMessaging messaging].APNSToken = deviceToken;
  </code></pre>
  
  <p>Of course Xcode project is all fine: provision profile is active, Target -> Background Modes -> Remote notifications -> Enabled, Target -> Push notifications -> ON. GoogleService-Info.plist is added to project.</p>
  
  <p>What's wrong? When Firebase SDK added and method swizzling disabled, didRegisterForRemoteNotificationsWithDeviceToken and didFailToRegisterForRemoteNotificationsWithError are never ever called. I tried to call:</p>
  
  <pre><code>[[UIApplication sharedApplication] registerForRemoteNotifications]
  </code></pre>
  
  <p>but no luck. Tried</p>
  
  <pre><code>requestAuthorizationWithOptions
  </code></pre>
  
  <p>and</p>
  
  <pre><code>if(granted) {
      [[UIApplication sharedApplication] registerForRemoteNotifications]
  </code></pre>
  
  <p>still nothing.</p>
  
  <h2>I missed something but I think it's either too simple or too difficult to find for me. Wasted two days to find but still no idea.</h2>
  
  <h2>UPDATE: I reproduced a problem in empty Objective-C project. It occurs when both Firebase iOS SDK and Firebase C++ SDK are implemented. If I remove Firebase C++ SDK frameworks, I can get my token again. Now when I can't get token I get "ERROR: Attempting to complete future before FCM initialized." in log.</h2>
  
  <p>Reproduce steps:</p>
  
  <ol>
  <li>Create Xcode project as usual. In my case it's a Game. Using Objective-C, Metal.</li>
  <li>On Capabilities->Background Modes->ON and Background Modes->Remote Notifications->Checked.</li>
  <li>Capabilities->Push Notifications->ON. Xcode shows enabled and no problems.</li>
  <li>On Firebase Console, created new app; added iOS app, bundle ID->download GoogleService-Info.plist and added to app.</li>
  <li>I don't use Cocoa Pods, so add following SDKs to iOS project: firebase.framework, firebase_instance_id.framework, firebase_messaging.framework, FirebaseCore.framework, FirebaseInstanceID.framework, FirebaseMessaging.framework, GoogleUtilities.framework, Protobuf.framework. These are frameworks from Firebase iOS SDK 5.17 and Firebase C++ SDK 5.5.0.</li>
  <li>Add UserNotifications.framework to project as Optional.</li>
  <li>Set iOS Deployment target to 9.0.</li>
  <li>Login to Apple Developer and create authentication key, and register it to Firebase console.</li>
  <li><p>In AppDelegate.m:</p>
  
  <h1>import "FirebaseCore/FIRApp.h"</h1>
  
  <h1>import "FirebaseMessaging/FIRMessaging.h"</h1>
  
  <h1>import </h1>
  
  <p>@interface AppDelegate ()  //&lt;-added 
  UNUserNotificationCenterDelegate</p>
  
  <ul>
  <li>(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  [FIRApp configure];
  if ([UNUserNotificationCenter class] != nil) {
  [UNUserNotificationCenter currentNotificationCenter].delegate = self;
  UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert |
  UNAuthorizationOptionSound | UNAuthorizationOptionBadge;
  [[UNUserNotificationCenter currentNotificationCenter]
  requestAuthorizationWithOptions:authOptions
  completionHandler:^(BOOL granted, NSError * _Nullable error) {
   printf("requestAuthorizationWithOptions granted=%d", granted);
  }];
  } else {
  UIUserNotificationType allNotificationTypes =
  (UIUserNotificationTypeSound | UIUserNotificationTypeAlert | UIUserNotificationTypeBadge);
  UIUserNotificationSettings *settings =
  [UIUserNotificationSettings settingsForTypes:allNotificationTypes categories:nil];
  [application registerUserNotificationSettings:settings];
  }
  [application registerForRemoteNotifications];</li>
  </ul></li>
  <li><p>Add methods to AppDelegate:</p>
  
  <ul>
  <li><p>(void)application:(UIApplication *)application 
  didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [FIRMessaging messaging].APNSToken = deviceToken;
  printf("didRegisterForRemoteNotificationsWithDeviceToken called!");
  }</p></li>
  <li><p>(void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
  printf("didFailToRegisterForRemoteNotificationsWithError");
  }</p></li>
  </ul></li>
  <li>In Info.plist add FirebaseAppDelegateProxyEnabled , type Boolean , set value to NO.</li>
  <li>Add -ObjC to target -> Other Linker Flags</li>
  <li>Add FirebaseImplement.cpp with hpp header to project. cpp contains only include hpp line.</li>
  <li>Run app. Log:
  2019-02-26 14:56:37.695107+0900 fcmtest2[821:126237] [DYMTLInitPlatform] platform initialization successful
  2019-02-26 14:56:37.734503+0900 fcmtest2[821:126088] FIID: Loading UIApplication FIRIID category
  2019-02-26 14:56:37.791910+0900 fcmtest2[821:126088] FCM: Loading UIApplication FIRFCM category
  2019-02-26 14:56:37.971120+0900 fcmtest2[821:126088] Setting up iOS 10 message delegate.
  2019-02-26 14:56:37.987322+0900 fcmtest2[821:126233] 5.17.0 - [Firebase/Core][I-COR000022] Firebase Analytics is not available. To add it, include Firebase/Core in the Podfile or add FirebaseAnalytics.framework to the Link Build Phase
  2019-02-26 14:56:38.106397+0900 fcmtest2[821:126088] Metal GPU Frame Capture Enabled
  2019-02-26 14:56:38.109046+0900 fcmtest2[821:126088] Metal API Validation Enabled
  2019-02-26 14:56:38.522326+0900 fcmtest2[821:126088] ERROR: Attempting to complete future before FCM initialized.
  requestAuthorizationWithOptions granted=1</li>
  <li>And neither didRegisterForRemoteNotificationsWithDeviceToken nor didFailToRegisterForRemoteNotificationsWithError are called.</li>
  </ol>