Skip to content

Commit

Permalink
Resolve request permission call when permission already exists
Browse files Browse the repository at this point in the history
Problem:
If permission is already enabled, the native call to `OneSignal.getNotifications().requestPermission(fallbackToSettings, Continue.with(...)` never suspends and the Continuation code block never runs. As a result, we would not be able to resolve the promise over the bridge.

Solution:
Before calling that method, do a permission check and return true early.
  • Loading branch information
nan-li committed Nov 6, 2023
1 parent 0421f61 commit 9680d81
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,10 @@ export namespace OneSignal {
if (!isNativeModuleLoaded(RNOneSignal)) {
return Promise.reject(new Error('OneSignal native module not loaded'));
}
// if permission already exists, return early as the native call will not resolve
if (hasPermission()) {
return Promise.resolve(true);
}

return RNOneSignal.requestNotificationPermission(fallbackToSettings);
}
Expand Down

0 comments on commit 9680d81

Please sign in to comment.