Mobile Notification Package iOS Location Trigger (Geofencing) not firing

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… :slight_smile:

  • Using the Geofence-Trigger is 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.

    private void ScheduleGeofencingNotification(Vector2 coord)
    {
    #if UNITY_IOS

         var locationTrigger = new iOSNotificationLocationTrigger()
    

    {
    Center = coord,
    Radius = 250f,
    NotifyOnEntry = true,
    NotifyOnExit = false,
    };
    var notification = new iOSNotification()
    {
    // You can optionally specify a custom identifier which can later be
    // used to cancel the notification, if you don’t set one, a unique
    // string will be generated automatically.
    Identifier = “_notification_02”,
    Title = “Title”,
    Body = “Scheduled by coordinate”,
    Subtitle = “This is a subtitle, something, something important…”,
    ShowInForeground = true,
    ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
    CategoryIdentifier = “category_a”,
    ThreadIdentifier = “thread1”,
    Trigger = locationTrigger,
    };

             iOSNotificationCenter.ScheduleNotification(notification);
    

    #endif

         }
    

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


3 Answers

3

I am thinking it is because of an internal bug in the Unity library, I have the following code to schedule a tigger and print the information of the scheduled notification.

 if (bSentNotification == false && GPSLocation.started)
 {
            var locationTrigger = new iOSNotificationLocationTrigger()
            {
                Center = new Vector2(22.4f, 114.2f),
                NotifyOnEntry = true,
                NotifyOnExit = true,
                Radius = 5.0f
            };

            var n = new iOSNotification()
            {
                Title = "This is title",
                Subtitle = "This is subtitle",
                Body = "This is body",
                ShowInForeground = true,
                ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
                Trigger = locationTrigger
            };
            iOSNotificationCenter.ScheduleNotification(n);
            Debug.Log("Started a location notification at " + locationTrigger.Center);

            bSentNotification = true;
        }
        else if(bSentNotification)
        {
            iOSNotification[] notifications = iOSNotificationCenter.GetScheduledNotifications();
            for(int i=0; i < notifications.Length; i++)
            {
                Debug.Log(((iOSNotificationLocationTrigger)notifications*.Trigger).Center);*

}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
[166657-screenshot-2020-09-01-at-125543-am.png_|166657]*
*
@mpeter_nmy Did you solve your problem already ? ,I am thinking it is because of an internal bug in the Unity library, I have the following code to schedule a tigger and print the information of the scheduled notification.
if (bSentNotification == false && GPSLocation.started)
{
var locationTrigger = new iOSNotificationLocationTrigger()
{
Center = new Vector2(22.4f, 114.2f),
NotifyOnEntry = true,
NotifyOnExit = true,
Radius = 5.0f
};

var n = new iOSNotification()
{
Title = “This is title”,
Subtitle = “This is subtitle”,
Body = “This is body”,
ShowInForeground = true,
ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
Trigger = locationTrigger
};
iOSNotificationCenter.ScheduleNotification(n);
Debug.Log("Started a location notification at " + locationTrigger.Center);

bSentNotification = true;
}
else if(bSentNotification)
{
iOSNotification[] notifications = iOSNotificationCenter.GetScheduledNotifications();
for(int i=0; i < notifications.Length; i++)
{
Debug.Log(((iOSNotificationLocationTrigger)notifications*.Trigger).Center);*
}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
[166657-screenshot-2020-09-01-at-125543-am.png|166657]_
_

@mpeter_nmy

Unforunately we had to go on in the project and couldn't figure out how to fix this issue ourselves. We are currently implementing this as a native background service. But anyways it would be great to come back to this functionality if it's working. I opened a ticket to report this on unity side but nothing happened since then...

I am thinking it could be because of an internal bug in the Unity library, I have the following code to schedule a tigger and print the information of the scheduled notification.

 if (bSentNotification == false && GPSLocation.started)
 {
            var locationTrigger = new iOSNotificationLocationTrigger()
            {
                Center = new Vector2(22.4f, 114.2f),
                NotifyOnEntry = true,
                NotifyOnExit = true,
                Radius = 5.0f
            };

            var n = new iOSNotification()
            {
                Title = "This is title",
                Subtitle = "This is subtitle",
                Body = "This is body",
                ShowInForeground = true,
                ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
                Trigger = locationTrigger
            };
            iOSNotificationCenter.ScheduleNotification(n);
            Debug.Log("Started a location notification at " + locationTrigger.Center);

            bSentNotification = true;
        }
        else if(bSentNotification)
        {
            iOSNotification[] notifications = iOSNotificationCenter.GetScheduledNotifications();
            for(int i=0; i < notifications.Length; i++)
            {
                Debug.Log(((iOSNotificationLocationTrigger)notifications*.Trigger).Center);*

}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
![alt text][1]
[1]: /storage/temp/166657-screenshot-2020-09-01-at-125543-am.png
@mpeter_nmy

It would be great to get an official response for this issue, this is not working at all.