requestPermission(): Promise<boolean>;
In practice, instead of resolving with true for agreement and false for disagreement, it resolves with undefined for agreement and rejects the promise for disagreement.
Here's my snippet that I wanted to use for initializing notification hooks:
messaging
.hasPermission()
.then((enabled) => enabled ? Promise.resolve(true) : messaging.requestPermission())
.then((agreed) => {
if (!agreed) { return; }
this.unsubOnNotificationOpened = notifications.onNotificationOpened(onNotificationOpened);
this.unsubOnNotification = notifications.onNotification(onNotification);
return notifications.getInitialNotification().then(onNotificationOpened);
})
.catch((error) => errorReporter.report(error));
agreed would be undefined for agreement and the reporter would catch some native error upon disagreement:
{"line":1,"column":4412,"framesToPop":1,"code":"messaging/permission_error","nativeStackIOS":["0 Guild 0x0000000105bc61c6 RCTJSErrorFromCodeMessageAndNSError + 134","1 Guild 0x0000000105b548e3 __41-[RCTModuleMethod processMethodSignature]_block_invoke_2.218 + 179","2 Guild 0x0000000105dc9ba9 __50-[RNFirebaseMessaging requestPermission:rejecter:]_block_invoke.266 + 137","3 libdispatch.dylib 0x000000010cad9177 _dispatch_call_block_and_release + 12","4 libdispatch.dylib 0x000000010cada1ba _dispatch_client_callout + 8","5 libdispatch.dylib 0x000000010cae1d3d _dispatch_queue_serial_drain + 654","6 libdispatch.dylib 0x000000010cae25a0 _dispatch_queue_invoke + 329","7 libdispatch.dylib 0x000000010cadec97 _dispatch_queue_override_invoke + 477","8 libdispatch.dylib 0x000000010cae4980 _dispatch_root_queue_drain + 568","9 libdispatch.dylib 0x000000010cae46ea _dispatch_worker_thread3 + 119","10 libsystem_pthread.dylib 0x000000010e853169 _pthread_wqthread + 1387","11 libsystem_pthread.dylib 0x000000010e852be9 start_wqthread + 13"],"userInfo":null,"domain":"RCTErrorDomain"}
iOS
macOS High Sierra
Xcode 9.2
React Native version:0.55.0
React Native Firebase Version:4.2.0
Firebase Module:messaging / notifications
typescript?yes
I am facing the same issue and I'm not using typescript
I have seen it resolve with 1 and 0 as well.
Will address both @andidev's issue and @mskv's. Lets continue the discussion in https://github.com/invertase/react-native-firebase/pull/1513#issuecomment-427621998 + see my comments there.
Most helpful comment
I have seen it resolve with 1 and 0 as well.