Search Unity

Official Mobile Notification Package

Discussion in 'Android' started by _Paulius, Jan 28, 2019.

  1. Revolter

    Revolter

    Joined:
    Mar 15, 2014
    Posts:
    216
    Submitted Bug Id: 1251504
     
  2. Deleted User

    Deleted User

    Guest

    Ah, okay. This crash has been fixed since 1.1.0-preview. Could you please update the package to the latest version and verify it again?
     
  3. habitoti

    habitoti

    Joined:
    Feb 28, 2013
    Posts:
    141
    I am using Unity 2019.3.15f1 and Mobile Notifications Package 1.2.1. I want to locally set the iOS app badge count while the app is running (so when I leave it it reflects the number of still open games). I am using this code:
    Code (CSharp):
    1. var notification = new Unity.Notifications.iOS.iOSNotification()
    2. {
    3.     ShowInForeground = true,
    4.     ForegroundPresentationOption = Unity.Notifications.iOS.PresentationOption.Badge,
    5.     Badge = count,
    6.     Trigger = new Unity.Notifications.iOS.iOSNotificationTimeIntervalTrigger()
    7.        { TimeInterval = new TimeSpan(0, 0, 0, 200), Repeats = false }
    8. };
    9.  
    10. Unity.Notifications.iOS.iOSNotificationCenter.ScheduleNotification(notification);
    which works, but it takes a few minutes until the badge is actually updated, and it is done with a notification sound (though I didn't allow that with the presentation options set above). Is there any other way (or a setting I missed) to set it more timely (read: instantly) and w/o any additional sound? Like when just clearing the badge, which works immediately and silently?

    EDIT:

    Maybe I was just thinking too complicated ;-)
    Looking through the Github repo of the Mobile Notification Package source, I found
    Code (CSharp):
    1. Unity.Notifications.iOS.iOSNotificationCenter.ApplicationBadge = count;
    which seems to nicely do the job :)
     
    Last edited: Jun 2, 2020
    NMJ_GD likes this.
  4. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    Hi, what is the recommended way to detect if notifications are allowed or not in app? We want to send some analytics up to see whether the user has declined notifications or not. We're trying to get the status of 'show notifications' for the app in the O/S but wondering if there was something for this in the package.

    This is for Android.
    We're on 1.0.4 and 2019.3.15

    thnx
     
  5. twice7713

    twice7713

    Joined:
    Apr 24, 2018
    Posts:
    24
    Vincent-Zhang
    Will you return on time in your case?
    I need your response, thank you very much.

    my case Example:
    I set someday/18:30:00
    but Notification time is someday/18:30:12
     
    Last edited: Jun 8, 2020
  6. twice7713

    twice7713

    Joined:
    Apr 24, 2018
    Posts:
    24
    and other error
    I set Reschedule on Device Restart true
    but restart device Notification not work
     
  7. Deleted User

    Deleted User

    Guest

    Could you please provide more info? Are you on Android or iOS? Are you setting repeatable or one-time notification?
     
  8. Deleted User

    Deleted User

    Guest

    Could you please make a bug report?
     
  9. DarrenDuck

    DarrenDuck

    Joined:
    Mar 7, 2016
    Posts:
    3
    Hello, it was said previously in this thread that:
    "you don't need to enable remote or push notifications to send local notifications, if you don't enable remote notifications in "Project Settings -> Mobile Notifications" your app should no longer require the Push Notification Entitlement."

    But the app store is giving us the message:
    "ITMS-90078: Missing Push Notification Entitlement - Your app appears to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement."

    As you can see in my attached screenshot we do not use push notifications, so how come we are getting this message?

    Mobile Notifications 1.2.1
    Unity 2019.2.17f1

    Thanks
     

    Attached Files:

  10. twice7713

    twice7713

    Joined:
    Apr 24, 2018
    Posts:
    24
    Notifications 1.2.1
    Android /Unity 2018.4.10 LTS
    Not on time happened to repeatable and one-time
     
  11. Deleted User

    Deleted User

    Guest

    On Android, we have to use AlarmManager to achieve the repeatale and time interval notifications.
    • For repeatable, AlarmManager.setInexactRepeating is used. You may ask why not using AlarmManager.setRepeating, according to the doc "as of API 19, all repeating alarms are inexact.". so repeatable notifications are not exact anyway.
    • For one-time, AlarmManager.set is used in our package, according to the doc " Beginning in API 19, the trigger time passed to this method is treated as inexact: the alarm will not be delivered before this time, but may be deferred and delivered some time later." The reason why we don't use AlarmManager.setExact is "Applications are strongly discouraged from using exact alarms unnecessarily as they reduce the OS's ability to minimize battery use."
    Can I ask why you need the time to be exact?
     
  12. Deleted User

    Deleted User

    Guest

    Could you please make a bug report? Thanks.
     
  13. twice7713

    twice7713

    Joined:
    Apr 24, 2018
    Posts:
    24
    In my project, there is a calendar alarm function, which needs to remind users on time.
    My partner say this Notification exact time.why not try that?
    so if i need exact time to work,I need to find other solution?

    Many thanks!
     
    Last edited: Jun 9, 2020
  14. twice7713

    twice7713

    Joined:
    Apr 24, 2018
    Posts:
    24
    Submitted Bug Id: 1251504
     
    Deleted User likes this.
  15. Deleted User

    Deleted User

    Guest

    Yes, the Notification at Android side notifies the notification immediately once you call NotificationManager.notify(). We use it internally as well, just we use the AlarmManager to decide when to call it.

    Do you think providing that API to trigger a notification (we can call it immediate mode notification) will help here? As you have to handle the timing to trigger by yourself.
     
    twice7713 likes this.
  16. mpeter_nmy

    mpeter_nmy

    Joined:
    Apr 2, 2019
    Posts:
    6
    I am currently trying to achieve the location-trigger functionality on iOS with this setup:

    - Unity-Editor: 2019.3.13f
    - mobile-notification package: 1.3.0
    - Test devices: iPad Pro (iOS 13.5) as well as several xcode simulator devices
    Permissions:
    - Push Notifactions are requested and allowed
    - Core Location Service requested and running with the "When in use" Permission

    Investigations

    - PushNotifications are triggered in foreground and background usage when using the timer based trigger. So far so good.... :)
    - Using the geofence-trigger notifications are not firing. I tried some coordinates/radius combinations with a real device first.
    - As this was not successfull i created a little project which is running in the xCode-DeviceSimulator. The GPS-Coordinates are updated with the "City-Run" debug mode. But the trigger is not firing ....
    - There are no errors in the debug console indicating something is going wrong

    Attached: Screenshots of Unity Settings as well as the App-Settings on iOS

    i would really appreciate to get some ideas what possibly could go wrong while using the GeoFence trigger feature

    locationtrigger.PNG
    mobileNotSetup.PNG
     
    Last edited: Jun 10, 2020
  17. Deleted User

    Deleted User

    Guest

    Could you please make a bug report about the location trigger not working issue? Thanks.
     
  18. mpeter_nmy

    mpeter_nmy

    Joined:
    Apr 2, 2019
    Posts:
    6
    thx!

    opened Case 1254664
     
  19. HankHongChen

    HankHongChen

    Joined:
    Jan 19, 2016
    Posts:
    4
    Hi there, I was trying the mobile notification for both iOS and Android. And I found that the notification was not show up on Android when the app was closed.

    I read the FAQ and know that because of the battery saver tech, most of the apps need to whitelist by the user to enable the notification when app is closed. But ask user to whitelist app at battery setting is not user friendly and as I know most of user find it difficult to whitelist a app.

    So I wonder, is there any chance that Unity will provide some options that can help workaround this issue? Like create a Sticky Service on android?

    Thanks a lot
     
  20. mathewsbabu

    mathewsbabu

    Joined:
    Sep 30, 2014
    Posts:
    33
    Crashed while taking Android Build
    Package Version 1.3.0
    Unity Version 2019.2.2f1
    Error Message

    stdout:
    IL2CPP error for method 'System.Void Unity.Notifications.Android.AndroidNotificationCenter::RegisterNotificationChannel(Unity.Notifications.Android.AndroidNotificationChannel)' in assembly
    Additional information: SafeArray element type Int64 is not supported.
    il2cpp.exe didn't catch exception: System.NotSupportedException: SafeArray element type Int64 is not supported.
    at Unity.IL2CPP.Marshaling.MarshalInfoWriters.ComSafeArrayMarshalInfoWriter.GetElementVariantType(MetadataType metadataType)
     
  21. Deleted User

    Deleted User

    Guest

    This bug https://issuetracker.unity3d.com/is...ompiling-a-struct-with-a-long-array-inside-it has been fixed in 2019.2.6f1, but your version is 2019.2.2f1.

    But we should have been updated the minimal version requirement for the package, will do that.
     
  22. mathewsbabu

    mathewsbabu

    Joined:
    Sep 30, 2014
    Posts:
    33
    Hi Vincent,
    thank you for the reply.Actually Package version 1.0.4 preview9 worked with Unity 2019.2.2f1.
    Anyway adding the minimal version would be great
    Regards
     
  23. mathewsbabu

    mathewsbabu

    Joined:
    Sep 30, 2014
    Posts:
    33
    hi @Vincent-Zhang ,
    I tried latest 1.3.0 package with Unity 2019.4.1f1 LTS.For Android pie
    1) Notification is showing but the icon is just a grey square.I have provided the notification icon in the editor(Mobile notifications bar in project settings).
    2) Also the notifications are not cleared when clicking them

    Any workaround/solution to this?
    Regards
     
    Last edited: Jun 23, 2020
  24. Deleted User

    Deleted User

    Guest

    #1, did you notice any warnings or errors? If not, please open a bug report with repro project, thanks.
    #2, You can set AndroidNotification.ShouldAutoCancel to true.
     
  25. Deleted User

    Deleted User

    Guest

    Yes, 1.0.4 preview9 did work with Unity 2019.2.2f1 as there's a workaround to fix this issue at package side. We removed the workaround in the new release as the fix at unity engine side is in 2019.2.6f1.
    Again, we definitely should have added the minimal version, my bad.
     
  26. mpeter_nmy

    mpeter_nmy

    Joined:
    Apr 2, 2019
    Posts:
    6
  27. mathewsbabu

    mathewsbabu

    Joined:
    Sep 30, 2014
    Posts:
    33
    #1 didn't notice any warning or error..Will double check..(Tried it in Xiaomi phone..Will that be a problem?)
    #2 How to set that?..In code itself ??
     
  28. Deleted User

    Deleted User

    Guest

  29. Deleted User

    Deleted User

    Guest

    Yes, in the code where you create an AndroidNotification.
     
  30. Gng357

    Gng357

    Joined:
    Oct 29, 2018
    Posts:
    3
    Hello,

    I'm using Mobile Notifications version 1.3.0 and I'm getting the following error:

    Code (CSharp):
    1. E/Unity: AndroidJavaException: java.lang.NoSuchMethodError: no static method with name='getNotificationManagerImpl' signature='(Landroid.app.Application;Lcom.unity3d.player.UnityPlayerActivity;)Ljava/lang/Object;' in class Ljava.lang.Object;
    2.     java.lang.NoSuchMethodError: no static method with name='getNotificationManagerImpl' signature='(Landroid.app.Application;Lcom.unity3d.player.UnityPlayerActivity;)Ljava/lang/Object;' in class Ljava.lang.Object;
    And here is my code:
    Code (CSharp):
    1.     public void CreateNotificationChannel()
    2.     {
    3.         /// Create Default Notification Channel.
    4.         defaultNotificationChannel = new AndroidNotificationChannel()
    5.         {
    6.             Id = "default_channel",
    7.             Name = "Default Channel",
    8.             Description = "For Generic notifications",
    9.             Importance = Importance.Default,
    10.         };
    11.  
    12.         /// Register Notification Channel we just created.
    13.         AndroidNotificationCenter.RegisterNotificationChannel(defaultNotificationChannel);
    14.     }
    15.  
    16.     public void SendNotification()
    17.     {
    18.         /// Schedule simple Text notification.
    19.         AndroidNotification notification = new AndroidNotification()
    20.         {
    21.             Title = "Test Notification",
    22.             Text = "This is a test notification!",
    23.             //SmallIcon = "app_icon_small",
    24.             //LargeIcon = "app_icon_large",
    25.             FireTime = System.DateTime.Now.AddSeconds(10),
    26.         };
    27.  
    28.         /// Send notification to the Notification Channel we created above.
    29.         identifier = AndroidNotificationCenter.SendNotification(notification, "default_channel");
    30.  
    31.     }
    Tested on Samsung Galaxy S7 Edge - Android 8 and Xiaomi Mi 5 Phone Android 8.

    Any ideas?
     
  31. KB73

    KB73

    Joined:
    Feb 7, 2013
    Posts:
    234
    We are seeing the same, on 2019.3.15 and Mobile Notifications 1.3.0

    We have gone through our own proguard to check - adding this seemed to fix it

    -keep class com.unity.androidnotifications.** { *;}
    -keepclassmembers class com.unity.androidnotifications.** { *;}
    -keepnames class com.unity.androidnotifications.** { *;}
    -keepclassmembernames class com.unity.androidnotifications.** { *;}

    This was found in the NotificationSamples forum on gitHub

    thnx


     
  32. Gng357

    Gng357

    Joined:
    Oct 29, 2018
    Posts:
    3
    I didn't have pro-guard file! So creating one like you suggested worked.

    Thank you.
     
  33. tam-pe

    tam-pe

    Joined:
    Sep 25, 2019
    Posts:
    2
    Hello, there is a conflict between Braze sdk and Unity Mobile Notifications package
    With a clean install of Braze, everything works well
    Pushes come events that push notifications are delivered to Unity

    The problem is that when the Unity Mobile Notifications package is connected, Braze messages in the Unity that the remote push notifications have been delivered stop working
    A small investigation showed that after connecting Unity Mobile Notifications methods from the AppboyUnityManager.mm class are no longer called didReceiveRemoteNotification

    Application logic, analytics, metrics are based on this functionality.
    Need help solving this issue.

    Thank you.
     
  34. DanilaVanilla

    DanilaVanilla

    Joined:
    Jul 4, 2016
    Posts:
    5
    Hello! I need to add tablets support. I have one small icon and a lot of large icons in Settings. After export project have:
    • drawable-hdpi-v11
    • drawable-ldpi-v11
    • drawable-mdpi-v11
    • drawable-xhdpi-v11
    • drawable-xxhdpi-v11 (without small icon).
    Where is xxxhdpi folder and why xxhdpi folder without small icon, and last question why folders have names with v11?
     
  35. GleyGames

    GleyGames

    Joined:
    Oct 16, 2015
    Posts:
    482
    Hello,
    Our plugin is based on notification asset from Unity. Official documentation can be found here:
    https://docs.unity3d.com/Packages/com.unity.mobile.notifications@1.3/manual/index.html
    Our asset is not offering any more functionality than the Unity one does so we cannot help you. Please address your question to Unity support since you need backend functionality.
    You can always ask for a refund by send us an email at gley.mobi@gmail.com
     
  36. goutham12

    goutham12

    Joined:
    Jul 14, 2016
    Posts:
    53
    Hi there!
    am using this package to my game. We have a requirement that is, display all delevered notification in the app.
    I mean i sheduled some notification while the app is running. think like it is deliverd (even the app is closed also), and i have button. when user clicks on this button i need to show all deleverd notification in a menu. how can i do that.
     
  37. delexaet

    delexaet

    Joined:
    Apr 14, 2016
    Posts:
    39
    For android, I would like to be able to execute certain custom behaviors when launching the app through various notifications. I was thinking when scheduling a notification, I'd update the IntentData of the AndroidNotification upon scheduling it.

    However in 1.3, I see in AndroidGameNotification, get/set for IntentData does not exist. I was wondering, is this on purpose? If so, could anyone explain why and how I might achieve my goal above?
     
  38. SahandMalaei

    SahandMalaei

    Joined:
    Aug 20, 2017
    Posts:
    2
    Hi, @Vincent-Zhang
    When do you think we will be able to use custom notification background images on Android? It would be a very nice addition to the package.
    Below is one such notification sent from the game Hitmasters.
    notification.png
     
  39. drallcom3

    drallcom3

    Joined:
    Feb 12, 2017
    Posts:
    165
    I really really want that, too.

    Since we're talking about that, does anyone know how to do that via Unity (not neccessarily with the Notification Package)?
     
  40. fakegood

    fakegood

    Joined:
    Oct 11, 2013
    Posts:
    31
    Hello, can i know why UnityNotificationData.m, UnityNotificationManager.m and UnityNotificationWrapper.m is included in tvOS platform when tvOS don't support notification. And it is causing xcode to have build failure.

    Is it tested that its working on tvOS?
     
  41. Alex_Bo

    Alex_Bo

    Joined:
    Sep 18, 2014
    Posts:
    16
    Hello! I try to make a simple notification for Android based on documentation:

    Code (CSharp):
    1.  
    2. var notification = new AndroidNotification();
    3. notification.Title = "Your Title";
    4. notification.Text = "Your Text";
    5. notification.FireTime = System.DateTime.Now.AddMinutes(1);
    6. AndroidNotificationCenter.SendNotification(notification, "channel_id");
    7.  
    Everything works. But once I add the interval property, the notification won't show:
    Code (CSharp):
    1.  
    2. notification.RepeatInterval = new TimeSpan(0, 2, 0);
    3.  
    Please advice.
     
  42. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    I'm getting a crash on iOS when trying to schedule a local notification with either a null body or null title field.

    The code responsible is here:

    This happens in push notifications package 1.3.0 and 1.0.3, and I'll have a guess that it happens in all the others as well.

    You need to check that title and body are not null before doing this:
    Code (csharp):
    1.  
    2.  NSString* title = [NSString localizedUserNotificationStringForKey: [NSString stringWithUTF8String: data->title] arguments: nil];
    3.  
    in the file UnityNotificationManager.m, like you do with the other fields.

    Sending a notification with a null body or title is desirable as sending a blank empty string title results in a local push notification with a gap where the title would be and it looks odd.


    Bug logged:
    Case 1276575


    Because this is a package I can't just change the code. It seems that occasionally the packages refresh or something and the change i make gets reverted. Is there a way i can stop that somehow?


    Edit: I tried it all again from the beginning and this time making a push with an empty string as the title didn't leave a gap on the notification so i'm not sure what was happening there. Still a null passed to notification services shouldn't crash the app.
     
    Last edited: Sep 10, 2020
  43. Antony-Blackett

    Antony-Blackett

    Joined:
    Feb 15, 2011
    Posts:
    1,778
    Me again:

    I found the whitespace title bug mentioned earlier happens if you need to reschedule notifications. I do this to change badge numbers.

    The bug happens because the iOSNotification gets initialised with " " white space so if you schedule a notification with and empty or null string it gets replaced with this white space if you need to get and then reschedule the notification.

    Changing the initialisation from:
    Code (csharp):
    1.  
    2. + (void)InitiOSNotificationData : (iOSNotificationData*) notificationData;
    3. {
    4.     notificationData -> title = " ";
    5.     notificationData -> body = " ";
    6.     notificationData -> badge = 0;
    7.     notificationData -> subtitle = " ";
    8.     notificationData -> categoryIdentifier = " ";
    9.     notificationData -> threadIdentifier = " ";
    10.     notificationData -> triggerType = PUSH_TRIGGER;
    11.     notificationData -> data = " ";
    12. }
    13.  
    to:
    Code (csharp):
    1.  
    2. + (void)InitiOSNotificationData : (iOSNotificationData*) notificationData;
    3. {
    4.     notificationData -> title = "";
    5.     notificationData -> body = "";
    6.     notificationData -> badge = 0;
    7.     notificationData -> subtitle = "";
    8.     notificationData -> categoryIdentifier = "";
    9.     notificationData -> threadIdentifier = "";
    10.     notificationData -> triggerType = PUSH_TRIGGER;
    11.     notificationData -> data = "";
    12. }
    13.  
    fixed the issue...

    However I'm now wondering if this will create other bugs on different iOS version.

    the other way to fix it would be to remove the length > 0 checks when creating iOSNotificationDatas

    Code (csharp):
    1.  
    2. if (content.title != nil && content.title.length > 0)
    3.  
    I think an empty string should be valid data for title and body.


    Here's a couple screenshots to illustrate the bug. On the left is with my fix removing whitespace. On the right is the current behaviour of the notifications package.
    Screen Shot 2020-09-11 at 11.15.41 AM.png
     
    Last edited: Sep 11, 2020
  44. michaeltepl

    michaeltepl

    Joined:
    Dec 26, 2013
    Posts:
    22
    Hi! We have problem using 1.3.0 package and Unity 2019.4.0.

    Often AndroidNotificationPostProcessor and iOSNotificationPostProcessor are not called when building application. So ios build fails, because capabilities are not added to xCode project. On Android, manifest doesnt contain receivers for notifications.

    This problem can be easily reproduced if you delete Library folder and perform clean build. Also in our project we have assembly definition, that contains references to Unity.Notifications.Android and Unity.Notification.iOS assemblies, maybe this somehow connected with the problem
     
    Last edited: Sep 25, 2020
  45. tiagotrigger

    tiagotrigger

    Joined:
    Mar 24, 2015
    Posts:
    4
    Hey guys, anyone knows how to clear the
    AndroidNotificationCenter.GetLastNotificationIntent()
    .

    I made a notification for opening a browser link, it works perfectly the first time, I get the link from intentData and call Application.OpenURL with it.
    But when I close the browser and reopen my app, the GetLastNotificationIntent() returns the same notification (previously opened). And because of it my code runs again opening the browser every time I open my app.

    Calling
    AndroidNotificationCenter.CancelNotification(id);
    changes nothing.
     
    max427857 likes this.
  46. max427857

    max427857

    Joined:
    Sep 9, 2020
    Posts:
    8
    May be useful to anyone, but be careful. (package 1.3.0)
    How to remove title in notifications:
    iOS: just send "" (empty string) to title (and read the messages above from Antony)
    Android: send null to title (It removed first line for androids API >= 24) (plugin code : setContentTitle(null))
     
  47. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Hi there,

    How do i check if notification permission is previously granted so i can set the status on switch control? (without asking for permission dialog)

    Please advise
     
  48. MaximPP

    MaximPP

    Joined:
    Jan 26, 2019
    Posts:
    76
    On Android, I can check if channel notifications are allowed using AndroidNotificationCenter.GetNotificationChannel(channel_id).Enabled, but how do I check if app notifications are allowed? When I disable notifications for the app, NotificationChannel continues to return Enabled==true
     
    jGate99 likes this.
  49. jGate99

    jGate99

    Joined:
    Oct 22, 2013
    Posts:
    1,945
    Same question , +1
     
  50. max427857

    max427857

    Joined:
    Sep 9, 2020
    Posts:
    8
    i used custom-write plugin (aar) with 1 method to check app notifications for android and it's strange that this method is not in this package.:confused:
     
    jGate99 likes this.