Skip to content

Commit d5614ce

Browse files
committed
Fix notification prompt callback firing w/ focus
Fix bug where the callback passed to promptForPushNotifications would fire false if there was a foreground event being processes by the SDK. This would happen in the following case: 1. if you prompted but the user backgrounded and foregrounded the app before answering the prompt. 2. If promptForPushNotifications was called before the SDK detected the app was foregrounded.
1 parent fadcee4 commit d5614ce

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationPermissionController.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ object NotificationPermissionController : PermissionsActivity.PermissionCallback
3636

3737
private val callbacks:
3838
MutableSet<OneSignal.PromptForPushNotificationPermissionResponseHandler> = HashSet()
39+
private var awaitingForReturnFromSystemSettings = false
3940

4041
init {
4142
PermissionsActivity.registerAsCallback(PERMISSION_TYPE, this)
@@ -97,6 +98,7 @@ object NotificationPermissionController : PermissionsActivity.PermissionCallback
9798
object : AlertDialogPrepromptForAndroidSettings.Callback {
9899
override fun onAccept() {
99100
NavigateToAndroidSettingsForNotifications.show(activity)
101+
awaitingForReturnFromSystemSettings = true
100102
}
101103
override fun onDecline() {
102104
fireCallBacks(false)
@@ -113,6 +115,8 @@ object NotificationPermissionController : PermissionsActivity.PermissionCallback
113115
}
114116

115117
fun onAppForegrounded() {
118+
if (!awaitingForReturnFromSystemSettings) return
119+
awaitingForReturnFromSystemSettings = false
116120
fireCallBacks(notificationsEnabled())
117121
}
118122

0 commit comments

Comments
 (0)