@@ -14,6 +14,19 @@ firebase._gIDAuthentication = null;
1414firebase . _cachedInvitation = null ;
1515firebase . _cachedDynamicLink = null ;
1616
17+ /**
18+ * Workaround function to call the `dispatch_get_main_queue(...)` for iOS
19+ * thanks to Alexander Ziskind found on:
20+ * http://nuvious.com/Blog/2016/7/5/calling-dispatch_async-in-nativescript
21+ */
22+ let invokeOnRunLoop = ( function ( ) {
23+ var runloop = CFRunLoopGetMain ( ) ;
24+ return function ( func ) {
25+ CFRunLoopPerformBlock ( runloop , kCFRunLoopDefaultMode , func ) ;
26+ CFRunLoopWakeUp ( runloop ) ;
27+ }
28+ } ( ) ) ;
29+
1730firebase . _addObserver = function ( eventName , callback ) {
1831 var queue = utils . ios . getter ( NSOperationQueue , NSOperationQueue . mainQueue ) ;
1932 return utils . ios . getter ( NSNotificationCenter , NSNotificationCenter . defaultCenter ) . addObserverForNameObjectQueueUsingBlock ( eventName , null , queue , callback ) ;
@@ -343,7 +356,9 @@ firebase._registerForRemoteNotifications = function () {
343356 app = utils . ios . getter ( UIApplication , UIApplication . sharedApplication ) ;
344357 }
345358 if ( app !== null ) {
346- app . registerForRemoteNotifications ( ) ;
359+ invokeOnRunLoop ( ( ) => {
360+ app . registerForRemoteNotifications ( ) ;
361+ } ) ;
347362 }
348363 } else {
349364 console . log ( "Error requesting push notification auth: " + error ) ;
@@ -388,7 +403,9 @@ firebase._registerForRemoteNotifications = function () {
388403 } else {
389404 var notificationTypes = UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationActivationModeBackground ;
390405 var notificationSettings = UIUserNotificationSettings . settingsForTypesCategories ( notificationTypes , null ) ;
391- app . registerForRemoteNotifications ( ) ; // prompts the user to accept notifications
406+ invokeOnRunLoop ( ( ) => {
407+ app . registerForRemoteNotifications ( ) ; // prompts the user to accept notifications
408+ } ) ;
392409 app . registerUserNotificationSettings ( notificationSettings ) ;
393410 }
394411} ;
0 commit comments