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 call to `OneSignal.getNotifications().requestPermission(fallbackToSettings, Continue.with(...)` never suspends and returns early and the Continue.with 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 fe96e72
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,13 @@ public void onNotificationPermissionChange(boolean permission) {

@ReactMethod
public void requestNotificationPermission(final boolean fallbackToSettings, Promise promise) {
// if permission already exists, no suspend is called so the Continue.with never runs below
boolean enabled = OneSignal.getNotifications().getPermission();
if (enabled) {
promise.resolve(true);
return;
}

OneSignal.getNotifications().requestPermission(fallbackToSettings, Continue.with(result -> {
if (result.isSuccess()) {
promise.resolve(result.getData());
Expand Down

0 comments on commit fe96e72

Please sign in to comment.