Search Unity

Mobile Notifications 2.0.0: Permission modal opening at launch & can't delay

Discussion in 'iOS and tvOS' started by jgmakes, Apr 27, 2022.

  1. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    I just added the Mobile Notifications 2.0.0 to my app and now it immediately presents a notification permission dialog when it starts. Before anything else happens.

    I've added this explicit call to ask for permissions purposefully very late in my game (actually a 2nd Scene). I assumed this late request would get rid of the automatic ask at launch, but it still happens:

    Code (CSharp):
    1.     IEnumerator RequestAuthorization()
    2.     {
    3.         var authorizationOption = AuthorizationOption.Alert | AuthorizationOption.Badge;
    4.         using (var req = new AuthorizationRequest(authorizationOption, true))
    5.         {
    6.             while (!req.IsFinished)
    7.             {
    8.                  yield return new WaitForFixedUpdate();
    9.             };
    10.             Debug.Log("done");
    11.         }
    12.     }
    I've now removed this request, and even got rid of all references and includes like
    using Unity.Notifications.iOS;
    , but the modal is still popping up immediately. It only stops if I remove Mobile Notifications through the Package Manager.

    One thing to note is that I've been using Firebase Cloud Messaging for at least a year or two in this project, and something similar used to happen with FCM causing an immediate permission ask (similar to this person's problem). I was able to get rid of it by being careful when I first referenced FCM code, and also by setting FirebaseMessagingAutoInitEnabled = false[/ICODE] in the Info.plist

    Is this problem because Mobile Notifications and Firebase Cloud Messaging are confusing one another and trying to manage the iOS notification systems at the same time?

    Anything else I should be trying?

    Unity 2019.4.16
    Mobile Notifications 2.0.0
    Firebase Cloud Messaging 8.8.0
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Go to Project Settings -> Mobile Notifications, there is a setting to automatically ask for permission on launch.
     
    xinatcg likes this.
  3. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    THANK YOU! You are amazing and saved the day, and probably my whole week :)

    I would log a note for the Unity product team that the user experience of receiving a permission request immediately upon opening an app is a very poor one. Unless it's Instagram or something everyone knows, a user doesn't know the value of the app yet, so they'll probably say no. It's the reason Apple strongly suggests waiting to ask until there's a clear reason to do so.

    If that's truly the case, perhaps it shouldn't default to recognized bad behavior like this.

    I also didn't see any means of doing this through the API (is there?) so I had no idea it existed. And if this is only possible via the Editor UI, is it mentioned in the documentation and I missed it?

    Again, thank you so much for helping Aurimas-Cernius, and I hope you don't mind, and take into consideration, improving the UX/docs for the developer, so we can improve the UX our users!

    For anyone who may stumble upon this:

    Screen Shot 2022-04-27 at 8.37.47 AM.png
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Good point that having that option on by default may not be the best thing.

    I don't understand the question. Are you asking about this:
    https://docs.unity3d.com/Packages/c...s_iOSSettings_RequestAuthorizationOnAppLaunch
     
  5. jgmakes

    jgmakes

    Joined:
    Jan 10, 2019
    Posts:
    75
    Yes, that's totally it! Thanks for much for the response!

    It's funny that the docs say,
    It's recommended to make the authorization request during the app's launch cycle.
    It's certainly easier for the developer, but it's been very documented that it's a very poor experience for the user, and in the end, for the business, if people reject the permission immediately. Apple's guidelines talk a lot about this practice.

    Also I think the docs with the example of the request for authorization, and a sample notification, should be updated to also include a snippet that demonstrates
    RequestAuthorizationOnAppLaunch = false;
    so folks like me don't miss it's an option.
     
  6. won-gyu

    won-gyu

    Joined:
    Mar 23, 2018
    Posts:
    35
    Hi, my Android devices ask for permission on launch. is there a configuration to disable it for Android?
     
  7. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    This happens when your app targets API level lower than 33. The permission request should happen the first time you touch notification, for example create notification channel. This request is asked automatically by OS itself. The only way around is to target SDK 33, then you have to ask for permission manually.
     
    won-gyu likes this.
  8. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11

    How to ask for the (notification)permission manually then? (for Android)
     
  9. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
  10. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    Thanks for the quick reply!

    I tried the code from the link you shared above but nothing happened when I ran the app. I've added the following code at the very start of the application right on the splash screen but I got no pop-up asking for notification permissions.
    I've also tried it calling on a button click but still nothing happened.

    Am I doing something wrong here?

    Here's the piece code I copied from the link you shared:
    "
    IEnumerator RequestNotificationPermission()
    {
    var request = new PermissionRequest();
    while (request.Status == PermissionStatus.RequestPending)
    yield return null;
    // here use request.Status to determine users response
    }

    "
     
  11. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    First of all, your app has to target SDK 33 and run on Android 13 to be able to ask for permission.
    Second, in order to test it, you need to delete app from device, otherwise Unity replaces existing app and notification permission is remembered from the past.
     
  12. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    Switched it to sdk 33, and built it on Android 13 devices (tried it on 2 devices) still nothing happened.
    (I always deleted the previous version from the phone before building the new one)
     
  13. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Can print out request.Status?
     
  14. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    While running in the editor on a Windows laptop I'm getting "RequestPending", but surprisingly when I'm building and running it on an Android 13 device it's printing nothing.
     
  15. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Use logcat package and examine what's printed there.
     
  16. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    upload_2023-8-3_14-1-2.png

    got these errors after the code was entered in that coroutine
     
  17. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Do you have minification enabled in Player Settings?
     
  18. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    upload_2023-8-3_15-41-4.png
    These are enabled in minification.
     
  19. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    Try disabling them. If that helps, then you need to update proguard settings.
    Latest version of notifications package should do that automatically, but older ones require manual work. You can make a project using newest package version and copy settings over for simplicity.
     
  20. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    it's working after disabling both the "Use R8" & "Release" checkboxes. I've 2 questions can you please answer these?

    1- First thing, will unchecking these 2 checkboxes gonna have any negative impact on other aspects of our app? (should I keep them unchecked from now on in my project)
    2- Secondly, I've tested it on Andriod 13, will it also gonna work on older Android versions using the same code** or do I have to do any other changes?

    Same code**
    IEnumerator RequestNotificationPermission()
    {
    var request = new PermissionRequest();
    while (request.Status == PermissionStatus.RequestPending)
    yield return null;
    // here use request.Status to determine users response
    }
     
  21. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,735
    These settings will disable minification&obfuscation of Java code. If that's not your concern, everything will just work. If you do want to use minification, either upgrade to 2.2.x or set exclusions in proguard file (you can make project using 2.2.x and copy the exclusions from it).

    It will work just fine. On older versions permission request will simply end right away with permission granted.
     
  22. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    okay thanks got it, but surprisingly while building apk it's building the project fine but when I tried building the app bundle (.aab) I got the following errors and the project is failing to build after disabling both the "Use R8" & "Release" checkboxes.

    upload_2023-8-7_17-36-28.png

    > Configure project :launcher
    WARNING: The option setting 'android.enableR8=false' is deprecated.
    It will be removed in version 5.0 of the Android Gradle plugin.
    You will no longer be able to disable R8
    > Task :launcher:preBuild UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:preBuild UP-TO-DATE
    > Task :unityLibrary:preBuild UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:preBuild UP-TO-DATE
    > Task :launcher:preReleaseBuild UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:preReleaseBuild UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:preReleaseBuild UP-TO-DATE
    > Task :unityLibrary:preReleaseBuild UP-TO-DATE
    > Task :UnityDataAssetPack:generateAssetPackManifest UP-TO-DATE
    > Task :launcher:generateReleaseResValues UP-TO-DATE
    > Task :unityLibrary:packageReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:packageReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:packageReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:compileReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:compileReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseRenderscript NO-SOURCE
    > Task :unityLibrary:generateReleaseResValues UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:generateReleaseResValues UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:generateReleaseResources UP-TO-DATE
    > Task :unityLibrary:generateReleaseResources UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:generateReleaseResValues UP-TO-DATE
    > Task :launcher:processReleaseAssetPackManifests UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:generateReleaseResources UP-TO-DATE
    > Task :launcher:linkReleaseManifestForAssetPacks UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:packageReleaseResources UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:extractDeepLinksRelease UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:processReleaseManifest UP-TO-DATE
    > Task :unityLibrary:packageReleaseResources UP-TO-DATE
    > Task :unityLibrary:extractDeepLinksRelease UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:packageReleaseResources UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseLibraryResources UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:extractDeepLinksRelease UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseAidl NO-SOURCE
    > Task :unityLibrary:compileReleaseLibraryResources UP-TO-DATE
    > Task :unityLibrary:generateReleaseBuildConfig UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:processReleaseManifest UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:parseReleaseLocalResources UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:compileReleaseLibraryResources UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:compileReleaseAidl NO-SOURCE
    > Task :unityLibrary:parseReleaseLocalResources UP-TO-DATE
    > Task :unityLibrary:compileReleaseAidl NO-SOURCE
    > Task :unityLibrary:javaPreCompileRelease UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:parseReleaseLocalResources UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:generateReleaseRFile UP-TO-DATE
    > Task :unityLibrary:mergeReleaseShaders UP-TO-DATE
    > Task :unityLibrary:compileReleaseShaders NO-SOURCE
    > Task :unityLibrary:generateReleaseAssets UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:generateReleaseBuildConfig UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:javaPreCompileRelease UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseJavaWithJavac UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:bundleLibCompileToJarRelease UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:bundleLibRuntimeToJarRelease UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:mergeReleaseShaders UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:compileReleaseShaders NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:generateReleaseAssets UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:packageReleaseAssets UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:processReleaseJavaRes NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:bundleLibResRelease NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:mergeReleaseJniLibFolders UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:mergeReleaseNativeLibs UP-TO-DATE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:stripReleaseDebugSymbols NO-SOURCE
    > Task :unityLibrary:GoogleMobileAdsPlugin.androidlib:copyReleaseJniLibsProjectOnly UP-TO-DATE
    > Task :unityLibrary:packageReleaseAssets
    > Task :unityLibrary:processReleaseJavaRes NO-SOURCE
    > Task :unityLibrary:bundleLibResRelease NO-SOURCE
    > Task :unityLibrary:mergeReleaseJniLibFolders UP-TO-DATE
    > Task :unityLibrary:mergeReleaseNativeLibs UP-TO-DATE
    > Task :unityLibrary:stripReleaseDebugSymbols UP-TO-DATE
    > Task :unityLibrary:copyReleaseJniLibsProjectOnly UP-TO-DATE
    > Task :unityLibrary:processReleaseManifest
    > Task :launcher:assetPackReleasePreBundleTask UP-TO-DATE
    > Task :launcher:compileReleaseRenderscript NO-SOURCE
    > Task :launcher:generateReleaseResources UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:generateReleaseRFile UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:generateReleaseBuildConfig UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:javaPreCompileRelease UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:compileReleaseJavaWithJavac UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:bundleLibCompileToJarRelease UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:bundleLibRuntimeToJarRelease UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:mergeReleaseShaders UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:compileReleaseShaders NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:generateReleaseAssets UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:packageReleaseAssets UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:processReleaseJavaRes NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:bundleLibResRelease NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:mergeReleaseJniLibFolders UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:mergeReleaseNativeLibs UP-TO-DATE
    > Task :unityLibrary:FirebaseApp.androidlib:stripReleaseDebugSymbols NO-SOURCE
    > Task :unityLibrary:FirebaseApp.androidlib:copyReleaseJniLibsProjectOnly UP-TO-DATE
    > Task :unityLibrary:generateReleaseRFile
    > Task :unityLibrary:compileReleaseJavaWithJavac UP-TO-DATE
    > Task :unityLibrary:bundleLibRuntimeToJarRelease UP-TO-DATE
    > Task :unityLibrary:bundleLibCompileToJarRelease UP-TO-DATE
    > Task :launcher:createReleaseCompatibleScreenManifests UP-TO-DATE
    > Task :launcher:extractDeepLinksRelease UP-TO-DATE
    > Task :launcher:processReleaseManifest
    C:\Users\adkar\OneDrive\Desktop\octothink_unity_appflyer\Library\Bee\Android\Prj\IL2CPP\Gradle\launcher\src\main\AndroidManifest.xml:4:2-98 Warning:
    uses-permission#android.permission.READ_EXTERNAL_STORAGE was tagged at AndroidManifest.xml:4 to replace another declaration but no other declaration present
    > Task :launcher:checkReleaseDuplicateClasses
    > Task :launcher:compileReleaseAidl NO-SOURCE
    > Task :launcher:generateReleaseBuildConfig UP-TO-DATE
    > Task :launcher:javaPreCompileRelease UP-TO-DATE
    > Task :launcher:mergeReleaseShaders UP-TO-DATE
    > Task :launcher:compileReleaseShaders NO-SOURCE
    > Task :launcher:generateReleaseAssets UP-TO-DATE
    > Task :launcher:mergeReleaseAssets
    > Task :launcher:processReleaseJavaRes NO-SOURCE
    > Task :launcher:mergeReleaseJniLibFolders UP-TO-DATE
    > Task :launcher:collectReleaseDependencies UP-TO-DATE
    > Task :launcher:configureReleaseDependencies UP-TO-DATE
    > Task :launcher:parseReleaseIntegrityConfig UP-TO-DATE
    > Task :launcher:validateSigningRelease UP-TO-DATE
    > Task :launcher:mergeReleaseResources
    > Task :launcher:bundleReleaseResources UP-TO-DATE
    aapt2.exe W 08-07 17:12:21 118148 84924 LoadedArsc.cpp:657] Unknown chunk type '200'.
    > Task :launcher:processReleaseResources
    > Task :launcher:compileReleaseJavaWithJavac
    > Task :launcher:dexBuilderRelease FAILED
    > Task :launcher:mergeReleaseJavaResource
    > Task :launcher:desugarReleaseFileDependencies
    > Task :launcher:mergeReleaseNativeLibs
    78 actionable tasks: 13 executed, 65 up-to-date
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)
     

    Attached Files:

  23. unity_52B9288CB7049A41C920

    unity_52B9288CB7049A41C920

    Joined:
    Sep 8, 2022
    Posts:
    11
    Any guess why that's happening?
     
  24. unity_3DC048C2CCB75049F012

    unity_3DC048C2CCB75049F012

    Joined:
    Dec 6, 2023
    Posts:
    1



    Helpful, Thanks