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

Lifecycle Issues with userNotificationsEnabled #246

Closed
Windisch94 opened this issue Dec 2, 2024 · 2 comments
Closed

Lifecycle Issues with userNotificationsEnabled #246

Windisch94 opened this issue Dec 2, 2024 · 2 comments

Comments

@Windisch94
Copy link

Windisch94 commented Dec 2, 2024

What Airship dependencies are you using?

18.4.1

What are the versions of any relevant development tools you are using?

Compose Lifecycle Version 2.8.7,
Gradle 8.7, target and compile sdk 35

Report

What unexpected behavior are you seeing?

When I use UAirship.shared().pushManager.userNotificationsEnabled = true it askes me for the permission (for android > 13) which is fine.
But i have a problem when the permission is already denied.
When I call the above line of code with denied notification permission it triggers a onPause -> onResume for my current lifecycle.
When I allow the notification the lifecycle change doesnt happen.

Code I use for lifecycle tracking:

LifecycleEventEffect(Lifecycle.Event.ON_RESUME) {
       ...
}

As I need to refresh some data in the resume case and also need to enable the notification on this place i have the unexpected behaviour because your code is triggering some lifecycle events.

Are there any workarounds for it?

@rlepinski
Copy link
Collaborator

The reason for this is its not possible for us to query the permission status on Android and know if the permission was previously denied or just not requested yet. On iOS, they have a not_determined state, but Android its just granted or denied. When you enable user notifications and the permission is denied, we start an activity to try to request it. This should only happen on the first enable call though.

We do have a workaround but it puts prompting for the permission on you. If you set isPromptForPermissionOnUserNotificationsEnabled = false on the Airship config, it will prevent our SDK from automatically prompting for the permission when UAirship.shared().pushManager.userNotificationsEnabled = true is called. You will have to prompt for the notification when you determine its necessary, but you can do it in the activity that you are having a lifecycle issue for and it should only go pause -> resume if a system prompt is actually launched to the user.

@Windisch94
Copy link
Author

@rlepinski thanks, didnt know about that flag. that would help a lot

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

No branches or pull requests

2 participants