- Home /
Unity iOS Push Notifications for Location
I think it's great that Unity now has built in support for push notifications...
I can't seem to get the location triggers to work on iOS...
I've implemented and got both time notifications and instant notifications to work.
Location Services also gets the correct lat lng...
I have also added CoreLocation framework in General/Frameworks in XCode
I have added both location info.plist permissions. As well as required background modes
Here's the code... TestPush.cs is kind of the control logic, and PushHelper.cs is an intermediary to abstractify the specific push commands LocationHelper.cs is returning the right lat lng (I've tried flipping the coordinates around too) / "Actually Send Push" also returns in the xcode debug logs... I believe I am properly authenticating, though I have also included that as a separate snippet below. Everything other than the location push seems to work.
public void SendPushNotificationHere()
{
lh.PollLatLng();
}
void ActuallySendPushNotificationLoc(Vector2 latlng)
{
print("Actually Send Push "+latlng);
ph.CreateLocationTrigger(latlng.y, latlng.x, 250, true, true, "Notify Loc", "Arrived", latlng.ToString("F4"),"here","location","location",null,true);
}
public void CreateLocationTrigger(float lat, float lng, float radius, bool notifyonentry, bool notifyonexit, string title, string subtitle, string body, string identifier = null, string thredidentifier = null, string categoryidentifier=null,string data=null, bool showinforeground = false)
{
var locationTrigger = new iOSNotificationLocationTrigger()
{
Center = new Vector2(lat, lng),
Radius = radius,
NotifyOnEntry = notifyonentry,
NotifyOnExit = notifyonexit
};
var notification = new iOSNotification()
{
// You can specify a custom identifier which can be used to manage the notification later.
// If you don't provide one, a unique string will be generated automatically.
Identifier = identifier,
Title = title,
Body = body,
Subtitle = subtitle,
ShowInForeground = showinforeground,
ForegroundPresentationOption = (PresentationOption.Alert | PresentationOption.Sound),
CategoryIdentifier = categoryidentifier,
ThreadIdentifier = thredidentifier,
Data = data,
Trigger = locationTrigger
};
iOSNotificationCenter.ScheduleNotification(notification);
}
Here is the plist screenshot - https://gyazo.com/278076a9e07767cbc926dc736bc6b421
void Start () { StartCoroutine(RequestAuthorization());
iOSNotificationCenter.OnRemoteNotificationReceived += remoteNotification =>
{
// When a remote notification is received, modify its contents and show it after 1 second.
var timeTrigger = new iOSNotificationTimeIntervalTrigger()
{
TimeInterval = new TimeSpan(0, 0, 1),
Repeats = false
};
iOSNotification notification = new iOSNotification()
{
Title = "Remote: " + remoteNotification.Title,
Body = "Remote: " + remoteNotification.Body,
Subtitle = "Remote: " + remoteNotification.Subtitle,
ShowInForeground = true,
ForegroundPresentationOption = PresentationOption.Sound | PresentationOption.Alert,
CategoryIdentifier = remoteNotification.CategoryIdentifier,
ThreadIdentifier = remoteNotification.ThreadIdentifier,
Trigger = timeTrigger,
};
iOSNotificationCenter.ScheduleNotification(notification);
};
}
IEnumerator RequestAuthorization() { var authorizationOption = AuthorizationOption.Alert | AuthorizationOption.Badge;
using (var req = new AuthorizationRequest(authorizationOption, true))
{
while (!req.IsFinished)
{
yield return null;
};
string res = "\n RequestAuthorization:";
res += "\n finished: " + req.IsFinished;
res += "\n granted : " + req.Granted;
res += "\n error: " + req.Error;
res += "\n deviceToken: " + req.DeviceToken;
Debug.Log(res);
while(!req.IsFinished)yield return new WaitForSeconds(0.1f);
if (req.Granted)
{
deviceToken = req.DeviceToken;
PermissionGranted();
}
else
{
PermissionDenied();
}
}
}
Am I calling the method wrong?
Am I missing some sort of permission or flip somewhere?
I've updated it also with how I am authenticating...
I'm not sure if deviceToken is automatically passed in via the Unity Notifications API?
There is an open issue for this, everyone go aheasd and vote for it please: https://issuetracker.unity3d.com/issues/ios-mobile-notification-iosnotificationlocationtrigger-is-not-firing-on-ios-devices
Your answer

Follow this Question
Related Questions
Push click - App opening problem - iOS 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Push Notification to start a scene 2 Answers
How to distinguish Firebase Push Notification received in Background and when App open 0 Answers
Unity 2017.4.0f1 compile issue when building for desktop 1 Answer