Skip to content

Commit

Permalink
Merge pull request #936 from OneSignal/v5_resolve_request_permission
Browse files Browse the repository at this point in the history
V5 resolve request permission
  • Loading branch information
nan-li authored Nov 9, 2023
2 parents c5fbb28 + 67d96f6 commit f395403
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/android/com/onesignal/cordova/OneSignalController.java
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ public static boolean requestPermission(CallbackContext callbackContext, JSONArr

OneSignal.getNotifications().requestPermission(fallbackToSettings, Continue.with(r -> {
if (r.isSuccess()) {
if (r.getData()) {
Boolean didPermit = r.getData();
CallbackHelper.callbackSuccessBoolean(callbackContext, didPermit);
}
CallbackHelper.callbackSuccessBoolean(callbackContext, r.getData());
} else {
// coroutine was not successful
CallbackHelper.callbackError(callbackContext, r.getThrowable().getMessage());
}
}));
return true;
Expand Down
4 changes: 4 additions & 0 deletions www/NotificationsNamespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default class Notifications {
* @returns {Promise<boolean>}
*/
requestPermission(fallbackToSettings?: boolean): Promise<boolean> {
// if permission already exists, return early as the native call will not resolve
if (this.hasPermission()) {
return Promise.resolve(true);
}
let fallback = fallbackToSettings ?? false;

return new Promise<boolean>((resolve, reject) => {
Expand Down

0 comments on commit f395403

Please sign in to comment.