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

[Bug]: com.onesignal.OneSignal$PromptForPushNotificationPermissionResponseHandler.response #606

Closed
1 task done
shefich opened this issue May 23, 2023 · 10 comments
Closed
1 task done

Comments

@shefich
Copy link

shefich commented May 23, 2023

What happened?

Can't reproduce the issue on my device. It started to happen after I switched from unity 2020 to unity 2021.

Steps to reproduce?

Here's a code I am using to get the issue:
'void Start () {		
		#if UNITY_IOS
				OneSignal.Default.Initialize("xxxx");
		#elif UNITY_ANDROID
				OneSignal.Default.Initialize("xxxx");
		#endif

		PromptForPush();
		OneSignal.Default.SetLaunchURLsInApp(false);
    }

public async void PromptForPush() {
        var result = await OneSignal.Default.PromptForPushNotificationsWithUserResponse();
    }
'

What did you expect to happen?

I expected to see allow notification popup probably.

Unity version

2021.3.25 (latest)

OneSignal Unity SDK version

3.0.11

Platform

Android

Relevant log output

main (native)
tid=1 systid=31868
Triggered ANR
Root blocking
0
libc.so
nanosleep + 8
1
libil2cpp.so
GC_lock
2
libil2cpp.so
GC_register_my_thread
3
libil2cpp.so
il2cpp::gc::GarbageCollector::RegisterThread(void*)
4
libil2cpp.so
il2cpp::vm::Thread::Attach(Il2CppDomain*)
5
libunity.so
scripting_thread_attach(ScriptingDomainPtr)
6
libunity.so
JavaToScriptingThreadAttach::JavaToScriptingThreadAttach(ScriptingDomainPtr)
7
libunity.so
UnityJavaProxy_invoke(_JNIEnv*, _jobject*, long, _jstring*, _jobjectArray*)
8
libart.so
art_quick_generic_jni_trampoline + 148
9
libart.so
nterp_helper + 1948
10
data@app@[email protected][email protected]@classes.vdex
com.unity3d.player.ReflectionHelper.a
11
libart.so
nterp_helper + 52
com.unity3d.player.ReflectionHelper.nativeProxyInvoke (Native method)
com.unity3d.player.ReflectionHelper.a (unavailable)
com.unity3d.player.ReflectionHelper$1.invoke (unavailable:29)
java.lang.reflect.Proxy.invoke (Proxy.java:1006)
com.onesignal.OneSignal$PromptForPushNotificationPermissionResponseHandler.response (OneSignal.java)
com.onesignal.NotificationPermissionController.fireCallBacks (NotificationPermissionController.kt:115)
com.onesignal.NotificationPermissionController.onAccept (NotificationPermissionController.kt:80)
com.onesignal.PermissionsActivity$1.run (PermissionsActivity.java:149)
android.os.Handler.handleCallback (Handler.java:942)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:226)
android.os.Looper.loop (Looper.java:313)
android.app.ActivityThread.main (ActivityThread.java:8757)
java.lang.reflect.Method.invoke (Native method)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

Code of Conduct

  • I agree to follow this project's Code of Conduct
@shepherd-l
Copy link
Contributor

Just to clarify, is your issue that the app crashes after calling PromptForPushNotificationsWithUserResponse()?

What devices is the issue occurring on and what version of Android are they on?

Could you try reproducing the issue and provide the steps when you are able to

@shefich
Copy link
Author

shefich commented May 24, 2023

I don't know what happened, as I see it is connected to the "PromptForPushNotificationPermissionResponseHandler" and probably somehow connected to the Unity 2021.3.25, but I'm not sure.
Android versions: 7,8,9,10,11,12, 13.
Devices: Redmi, Motorolla, Samsung, LGE, BLU, and many others

@shefich
Copy link
Author

shefich commented May 26, 2023

@shepherd-l should PromptForPushNotificationsWithUserResponse() should be called everytime and SDK checks if the popup should be shown? Or there is some code logic to check if we need to ask for prompt?

@shepherd-l
Copy link
Contributor

PromptForPushNotificationsWithUserResponse() does not contain any code logic to check if we need to prompt the user

We recommend following our guide on how to prompt the user for push permission
Push Prompting

How to Prompt for Push Permissions with In-App Messages

Let us know if you have any questions!

@shefich
Copy link
Author

shefich commented May 26, 2023

@shepherd-l thank you for you answer.
I found the needed code example here: https://documentation.onesignal.com/docs/how-to-prompt-for-push-permissions-with-an-in-app-message
OSDeviceState device = OneSignal.getDeviceState(); boolean areNotificationsEnabled = device.areNotificationsEnabled();

Based on your links and the one above the code should look like this:
OneSignal.Default.Initialize("xxx-xxx-xxx-xxx-xxx"); OSDeviceState device = OneSignal.getDeviceState(); boolean areNotificationsEnabled = device.areNotificationsEnabled(); if !areNotificationsEnabled { OneSignal.promptForPushNotifications(); }

Am I right?

@shepherd-l
Copy link
Contributor

shepherd-l commented May 26, 2023

getDeviceState() is a Android SDK method and not available on our Unity SDK

I believe in Unity it would look something like this:

var currentStatus = OneSignal.Default.NotificationPermission;
if (currentStatus == NotificationPermission.NotDetermined) {
   OneSignal.Default.PromptForPushNotificationsWithUserResponse();
}

You can see Push Notification Properties code samples here and the types of Notification Permission Statuses here

Sorry for the confusion. That guide code example is specifically for Android. Thanks for bringing it up, we could update our docs to include code samples for our other SDKs.

@shefich
Copy link
Author

shefich commented May 29, 2023

@shepherd-l your code gives alert: Because this call is not awaited, execution of the current method continues before the call is completed.
Probably you need to add await before calling for prompt in order to fix the alert.

var currentStatus = OneSignal.Default.NotificationPermission;
if (currentStatus == NotificationPermission.NotDetermined) {
   await OneSignal.Default.PromptForPushNotificationsWithUserResponse();
}

@shepherd-l
Copy link
Contributor

Yes sorry, I forgot to include await in my code example

PromptForPushNotificationsWithUserResponse() also returns a NotificationPermission type

For example :

var response = await OneSignal.Default.PromptForPushNotificationsWithUserResponse();
if (response == NotificationPermission.Authorized) {
    // user accepted
}

You can also see our included example MonoBehaviour for some sample usage

Our migration guide also includes some 3.x.x code samples

@rakshitbharat
Copy link

everything is now messed up

@shepherd-l
Copy link
Contributor

We have had no further reports of this. Please upgrade the OneSignal SDK if you or anyone is still having this issue. If this is still an issue, please open a new report with updated information.

@rakshitbharat
Could you open a new issue and fill out the information for more visibility

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

3 participants