Skip to content

Commit 45377b7

Browse files
authored
Merge pull request #218 from Unity-Technologies/ios-location-improvements
iOS Location improvements and fixes
2 parents 1b641d5 + 8c56551 commit 45377b7

File tree

10 files changed

+69
-24
lines changed

10 files changed

+69
-24
lines changed

TestProjects/Main/Assets/Resources/iOSNotifications/LocationTrigger/Location Triggered.asset

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ MonoBehaviour:
1313
m_Name: Location Triggered
1414
m_EditorClassIdentifier:
1515
ButtonName: Send A Notification (Location Trigger)
16-
Identifier:
16+
Identifier: loc_not
1717
CategoryIdentifier: category_indentifier
1818
ThreadIdentifier: thread_identifier
1919
Title: Location Notification Title
2020
Subtitle: This is a subtitle
2121
Body: And this is the body of this notification
22-
ShowInForeground: 0
22+
ShowInForeground: 1
2323
PresentationOptions: 6
2424
Badge: -1
2525
Data: This notification also includes some data
26-
CenterX: 22.2847
27-
CenterY: 114.1582
26+
Latitude: 22.2847
27+
Longitude: 114.1582
2828
Radius: 5000
2929
NotifyOnEntry: 1
3030
NotifyOnExit: 1
31+
Repeats: 1

TestProjects/Main/Assets/Scripts/ScriptableObjects/iOSNotificationTemplateLocationTrigger.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ public class iOSNotificationTemplateLocationTrigger : ScriptableObject
3434

3535
[Space(10)]
3636
[Header("Location Trigger")]
37-
public float CenterX = 0f;
38-
public float CenterY = 0f;
37+
public double Latitude = 0f;
38+
public double Longitude = 0f;
3939
public float Radius = 2f;
4040
public bool NotifyOnEntry = true;
4141
public bool NotifyOnExit = false;
42+
public bool Repeats = false;
4243
#endif
4344
}
4445
}

TestProjects/Main/Assets/Scripts/iOSTest.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,12 @@ private void InstantiateAllTestButtons()
321321
Data = template.Data,
322322
Trigger = new iOSNotificationLocationTrigger()
323323
{
324-
Center = new Vector2(template.CenterX, template.CenterY),
324+
Latitude = template.Latitude,
325+
Longitude = template.Longitude,
325326
Radius = template.Radius,
326327
NotifyOnEntry = template.NotifyOnEntry,
327-
NotifyOnExit = template.NotifyOnExit
328+
NotifyOnExit = template.NotifyOnExit,
329+
Repeats = template.Repeats,
328330
}
329331
}
330332
);
@@ -344,13 +346,13 @@ private void InstantiateAllTestButtons()
344346
Transform buttonGroup =
345347
GameObject.Instantiate(m_gameObjectReferences.ButtonGroupTemplate, m_gameObjectReferences.ButtonScrollViewContent);
346348
Transform buttonGroupName = buttonGroup.GetChild(0).transform;
347-
Transform buttonGameObject = buttonGroup.GetChild(1).transform;
349+
Transform buttonGameObject = buttonGroup.GetChild(1).GetChild(0).transform;
348350
// Set group name
349351
buttonGroupName.GetComponentInChildren<Text>().text = group.Key.ToString();
350352
// Instantiate buttons
351353
foreach (DictionaryEntry test in group.Value)
352354
{
353-
Transform button = GameObject.Instantiate(buttonGameObject, buttonGroup);
355+
Transform button = GameObject.Instantiate(buttonGameObject, buttonGroup.GetChild(1));
354356
button.gameObject.GetComponentInChildren<Text>().text = test.Key.ToString();
355357
button.GetComponent<Button>().onClick.AddListener(delegate
356358
{
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0"?>
2+
<gpx version="1.1" creator="Xcode">
3+
<!-- A location used by location trigger button -->
4+
<wpt lat="22.2847" lon="114.1582">
5+
<name>Somewhere</name>
6+
</wpt>
7+
</gpx>

com.unity.mobile.notifications/Documentation~/iOS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ In the example below, the center coordinate is defined using the WGS 84 system.
123123
```c#
124124
var locationTrigger = new iOSNotificationLocationTrigger()
125125
{
126-
Center = new Vector2(2.294498f, 48.858263f),
126+
Latitude = 48.858263,
127+
Longitude = 2.294498,
127128
Radius = 250f,
128129
NotifyOnEntry = true,
129130
NotifyOnExit = false,

com.unity.mobile.notifications/Runtime/iOS/Plugins/UnityNotificationData.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ typedef struct iOSNotificationData
6464

6565
struct
6666
{
67-
float centerX;
68-
float centerY;
67+
double latitude;
68+
double longitude;
6969
float radius;
7070
unsigned char notifyOnEntry;
7171
unsigned char notifyOnExit;
72+
unsigned char repeats;
7273
} location;
7374
} trigger;
7475
} iOSNotificationData;

com.unity.mobile.notifications/Runtime/iOS/Plugins/UnityNotificationData.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ iOSNotificationData UNNotificationRequestToiOSNotificationData(UNNotificationReq
164164
UNLocationNotificationTrigger* locationTrigger = (UNLocationNotificationTrigger*)request.trigger;
165165
CLCircularRegion *region = (CLCircularRegion*)locationTrigger.region;
166166

167-
notificationData.trigger.location.centerX = region.center.latitude;
168-
notificationData.trigger.location.centerY = region.center.longitude;
167+
notificationData.trigger.location.latitude = region.center.latitude;
168+
notificationData.trigger.location.longitude = region.center.longitude;
169169
notificationData.trigger.location.radius = region.radius;
170170
notificationData.trigger.location.notifyOnExit = region.notifyOnEntry;
171171
notificationData.trigger.location.notifyOnEntry = region.notifyOnExit;
172+
notificationData.trigger.location.repeats = locationTrigger.repeats;
172173
#endif
173174
}
174175
else if ([request.trigger isKindOfClass: [UNPushNotificationTrigger class]])

com.unity.mobile.notifications/Runtime/iOS/Plugins/UnityNotificationManager.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,14 @@ - (void)scheduleLocalNotification:(iOSNotificationData*)data
335335
else if (data->triggerType == LOCATION_TRIGGER)
336336
{
337337
#if UNITY_USES_LOCATION
338-
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(data->trigger.location.centerX, data->trigger.location.centerY);
338+
CLLocationCoordinate2D center = CLLocationCoordinate2DMake(data->trigger.location.latitude, data->trigger.location.longitude);
339339

340340
CLCircularRegion* region = [[CLCircularRegion alloc] initWithCenter: center
341341
radius: data->trigger.location.radius identifier: identifier];
342342
region.notifyOnEntry = data->trigger.location.notifyOnEntry;
343343
region.notifyOnExit = data->trigger.location.notifyOnExit;
344344

345-
trigger = [UNLocationNotificationTrigger triggerWithRegion: region repeats: NO];
345+
trigger = [UNLocationNotificationTrigger triggerWithRegion: region repeats: data->trigger.location.repeats];
346346
#else
347347
return;
348348
#endif

com.unity.mobile.notifications/Runtime/iOS/iOSNotification.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,12 @@ internal struct CalendarTriggerData
8282
[StructLayout(LayoutKind.Sequential)]
8383
internal struct LocationTriggerData
8484
{
85-
public float centerX;
86-
public float centerY;
85+
public double latitude;
86+
public double longitude;
8787
public float radius;
8888
public Byte notifyOnEntry;
8989
public Byte notifyOnExit;
90+
public Byte repeats;
9091
}
9192

9293
[StructLayout(LayoutKind.Explicit)]
@@ -348,11 +349,12 @@ public iOSNotificationTrigger Trigger
348349
case iOSNotificationTriggerType.Location:
349350
{
350351
var trigger = (iOSNotificationLocationTrigger)value;
351-
data.trigger.location.centerX = trigger.Center.x;
352-
data.trigger.location.centerY = trigger.Center.y;
352+
data.trigger.location.latitude = trigger.Latitude;
353+
data.trigger.location.longitude = trigger.Longitude;
353354
data.trigger.location.notifyOnEntry = (byte)(trigger.NotifyOnEntry ? 1 : 0);
354355
data.trigger.location.notifyOnExit = (byte)(trigger.NotifyOnExit ? 1 : 0);
355356
data.trigger.location.radius = trigger.Radius;
357+
data.trigger.location.repeats = (byte)(trigger.Repeats ? 1 : 0);
356358
break;
357359
}
358360
case iOSNotificationTriggerType.Push:
@@ -394,10 +396,12 @@ public iOSNotificationTrigger Trigger
394396
case iOSNotificationTriggerType.Location:
395397
return new iOSNotificationLocationTrigger()
396398
{
397-
Center = new Vector2(data.trigger.location.centerX, data.trigger.location.centerY),
399+
Latitude = data.trigger.location.latitude,
400+
Longitude = data.trigger.location.longitude,
398401
Radius = data.trigger.location.radius,
399402
NotifyOnEntry = data.trigger.location.notifyOnEntry != 0,
400-
NotifyOnExit = data.trigger.location.notifyOnExit != 0
403+
NotifyOnExit = data.trigger.location.notifyOnExit != 0,
404+
Repeats = data.trigger.location.repeats != 0,
401405
};
402406
case iOSNotificationTriggerType.Push:
403407
return new iOSNotificationPushTrigger();

com.unity.mobile.notifications/Runtime/iOS/iOSNotificationTriggers.cs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,29 @@ public struct iOSNotificationLocationTrigger : iOSNotificationTrigger
6262
/// <summary>
6363
/// The center point of the geographic area.
6464
/// </summary>
65-
public Vector2 Center { get; set; }
65+
[Obsolete("Use Latitude and Longitude", false)]
66+
public Vector2 Center
67+
{
68+
get
69+
{
70+
return new Vector2((float)Latitude, (float)Longitude);
71+
}
72+
set
73+
{
74+
Latitude = value.x;
75+
Longitude = value.y;
76+
}
77+
}
78+
79+
/// <summary>
80+
/// The latitude of the center point of the geographic area.
81+
/// </summary>
82+
public double Latitude { get; set; }
83+
84+
/// <summary>
85+
/// The longitude of the center point of the geographic area.
86+
/// </summary>
87+
public double Longitude { get; set; }
6688

6789
/// <summary>
6890
/// The radius (measured in meters) that defines the geographic area’s outer boundary.
@@ -78,6 +100,11 @@ public struct iOSNotificationLocationTrigger : iOSNotificationTrigger
78100
/// When this property is enabled, a device crossing from inside the region to outside the region triggers the delivery of a notification
79101
/// </summary>
80102
public bool NotifyOnExit { get; set; }
103+
104+
/// <summary>
105+
/// Whether the notification should repeat.
106+
/// </summary>
107+
public bool Repeats { get; set; }
81108
}
82109

83110
/// <summary>

0 commit comments

Comments
 (0)