Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] Add Android 13 push permission prompting #1415

Merged
merged 4 commits into from
Aug 1, 2022

Conversation

nan-li
Copy link
Contributor

@nan-li nan-li commented Jul 31, 2022

Description

One Line Summary

This PR implements push permission prompting in Android for Android 13 devices.

Details

Motivation

This is a new Android 13 features/requirement.

Scope

Push permission prompting on Android 13 devices. In order to not immediately be prompted in Android 13, apps will need to set their Android target SDK version to 33+.

Pre-existing OneSignal.PromptForPushNotificationsWithUserResponse method has the following changes:

  • Works on Android
  • Added an optional fallbackToSettings option.
promptForPushNotificationsWithUserResponse(fallbackToSettings?: boolean, handler?: (response: boolean) => void)

Testing

Manual testing

I tested on physical iPhone 13 and Android emulator on API 33 using combinations of allowing, denying, changing the permission in settings, and re-prompting. These are the ways of calling the method tested.

OneSignal.promptForPushNotificationsWithUserResponse();

OneSignal.promptForPushNotificationsWithUserResponse(true);

OneSignal.promptForPushNotificationsWithUserResponse(false);

OneSignal.promptForPushNotificationsWithUserResponse(res => console.log(res));

OneSignal.promptForPushNotificationsWithUserResponse(undefined, (res) => console.log(res));

OneSignal.promptForPushNotificationsWithUserResponse(true, (res) => console.log(res));

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
    • Prompting
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

This change is Reviewable

* Implement the call to `promptForPushNotifications` in the Android plugin
* Add `fallbackToSettings` boolean to the public API for the method `promptForPushNotificationsWithUserResponse()` to allow users to set this boolean.
* Update the iOS plugin to pass this boolean
* Nit: The iOS bridge had an additional remnant method called `promptForPushNotificationPermissions` that is not used, so remove it.
* This update also required setting `android:exported` in the Manifest
* Since we have a button to prompt for push, let's not prompt right away in OneSignal initialization
@nan-li nan-li mentioned this pull request Jul 31, 2022
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, just one nit, if that is addressed can merge without anther approval.

Reviewed 8 of 8 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @kesheshyan and @nan-li)


src/index.ts line 186 at r1 (raw file):

        if (!isNativeModuleLoaded(RNOneSignal)) return;

        var fallbackToSettings = false;

nit, should use let instead of var.

* Use `const` and `let` instead of `var`. Can be added to future lint rules for this SDK and Cordova SDK
@nan-li nan-li merged commit ccc89b5 into main Aug 1, 2022
@nan-li nan-li deleted the add/android_notification_permission_prompting branch August 1, 2022 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants