Unity iOS Push Notifications for Location Triggers

Viewed 502

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...

Here's the code... with relevant snippet included below.

 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

Also, here is the request authorization portion (though actually I am not sure how to send this authorization deviceToken with the actual location trigger, as exposed from the Unity side):

void Start ()
{
    StartCoroutine(RequestAuthorization()); 
}

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?
  • Should I be sending the deviceToken in the location trigger call?
0 Answers
Related