0
\$\begingroup\$

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... 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?
\$\endgroup\$
6
  • \$\begingroup\$ Can you show us a Minimal Complete Verifiable Example of the code you're using to trigger the location notification, and walk us through the steps you're taking to test it? This can help us spot whether there's a missing step anywhere. \$\endgroup\$ – DMGregory Jul 16 '20 at 11:01
  • \$\begingroup\$ updated with a link... i'm wondering if there is just some setting or something actually quite trivial i forgot to specify somewhere? \$\endgroup\$ – ina Jul 17 '20 at 20:47
  • \$\begingroup\$ Please place the example code we need inside your question itself, not in external links. \$\endgroup\$ – DMGregory Jul 17 '20 at 21:37
  • \$\begingroup\$ well it references other things.. but maybe i'm calling the CreateLocationTrigger incorrectly? added that snippet just now \$\endgroup\$ – ina Jul 18 '20 at 3:07
  • \$\begingroup\$ We still don't have a complete walkthrough of the steps we need to take to reproduce the problem. This is going to make it much slower to get high-quality, useful answers. \$\endgroup\$ – DMGregory Jul 18 '20 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.