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.... :)
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
Answer by WilliamWong · Aug 31, 2020 at 10:39 PM
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[i].Trigger).Center);
}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
@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[i].Trigger).Center);
}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
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...
Answer by WilliamWong · Aug 31, 2020 at 05:14 PM
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[i].Trigger).Center);
}
}
However, the printed out Center are different. Actually the value of longitude is now same as latitude.
Answer by lucas_martinic · Aug 12, 2021 at 02:03 PM
It would be great to get an official response for this issue, this is not working at all.
Your answer
Follow this Question
Related Questions
Trying to Build GPS Tracking Based App, Help 0 Answers
LocationServices on iOS provides much higher measurements than on Android 0 Answers
How to get device location in double insead of float 0 Answers
GPS power consumption 0 Answers
How to change a public location,how to get a public variable 1 Answer