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... Everything other than the location push seems to workI 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);
}
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?