Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ina · Jul 16, 2020 at 04:44 AM · iospush notification

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Wolfram · Sep 21, 2020 at 09:38 AM 0
Share

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

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

162 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges