Skip to content

Commit d6b0c8a

Browse files
committed
Merge branch 'master' of github.com:Unity-Technologies/com.unity.mobile.notifications into android-exact-scheduling
2 parents bfd95b3 + 555fc56 commit d6b0c8a

File tree

18 files changed

+247
-112
lines changed

18 files changed

+247
-112
lines changed

.yamato/promotion.yml

Lines changed: 0 additions & 83 deletions
This file was deleted.

.yamato/upm-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
test_editors:
22
- version: trunk
3+
- version: 2022.2
34
- version: 2022.1
45
- version: 2021.3
56
- version: 2020.3
6-
- version: 2019.4
77

88
test_players:
99
- version: trunk
10+
- version: 2022.2
1011
- version: 2022.1
1112
- version: 2021.3
1213
- version: 2020.3

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/AndroidTest.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ void Start()
9393
((Action)m_groups["Channels"]["Create Secondary Simple Channel"]).Invoke();
9494
((Action)m_groups["Channels"]["Create Fancy Channel"]).Invoke();
9595
m_LOGGER.Clear().White("Welcome!");
96+
97+
HandleNotificationPermission();
9698
HandleLastNotificationIntent();
9799
}
98100

@@ -103,10 +105,25 @@ void OnApplicationPause(bool isPaused)
103105
.Gray($"isPaused = {isPaused}", 1);
104106
if (isPaused == false)
105107
{
108+
HandleNotificationPermission();
106109
HandleLastNotificationIntent();
107110
}
108111
}
109112

113+
private void HandleNotificationPermission()
114+
{
115+
var permission = AndroidNotificationCenter.UserPermissionToPost;
116+
switch (permission)
117+
{
118+
case PermissionStatus.Allowed:
119+
m_LOGGER.Green("Permission granted to post notifications");
120+
break;
121+
default:
122+
m_LOGGER.Red("No permission to post notifications: " + permission);
123+
break;
124+
}
125+
}
126+
110127
private void HandleLastNotificationIntent()
111128
{
112129
AndroidNotificationIntentData notificationIntentData = AndroidNotificationCenter.GetLastNotificationIntent();
@@ -159,6 +176,7 @@ private void InstantiateAllTestButtons()
159176
m_groups["General"]["Open Settings"] = new Action(() => { AndroidNotificationCenter.OpenNotificationSettings(); });
160177
m_groups["General"]["Notification batch size: "+NotificationBatchSizes[_CurrentNotificationBatchSizeIndex]] = new Action(() => { ChangeNotificationBatchSize(NotificationBatchSizes); });
161178
m_groups["General"]["Reset notification counter"] = new Action(() => { NotificationCounter = 0; });
179+
m_groups["General"]["Request permission"] = new Action(() => { RequestNotificationPermission(); });
162180

163181
m_groups["Modify"] = new OrderedDictionary();
164182
//m_groups["Modify"]["Create notification preset"] = new Action(() => { });
@@ -270,6 +288,31 @@ private void InstantiateAllTestButtons()
270288
m_gameObjectReferences.ButtonGroupTemplate.gameObject.SetActive(false);
271289
}
272290

291+
void RequestNotificationPermission()
292+
{
293+
var permission = AndroidNotificationCenter.UserPermissionToPost;
294+
if (permission == PermissionStatus.Allowed)
295+
m_LOGGER.Green("Already authorized");
296+
if (permission == PermissionStatus.DeniedDontAskAgain)
297+
m_LOGGER.Red("Denied, don't ask again");
298+
else
299+
{
300+
m_LOGGER.Blue("Requesting permission");
301+
permission = AndroidNotificationCenter.RequestPermissionToPost();
302+
switch (permission)
303+
{
304+
case PermissionStatus.Allowed:
305+
m_LOGGER.Green("Permission granted");
306+
break;
307+
case PermissionStatus.RequestPending:
308+
return;
309+
default:
310+
m_LOGGER.Red(permission.ToString());
311+
break;
312+
}
313+
}
314+
}
315+
273316

274317
public void ChangeNotificationBatchSize(int[] notificationBatchSizes)
275318
{

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/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to this package will be documented in this file.
44

5+
## [2.1.0] - 2022-09-01
6+
7+
TODO
8+
59
## [2.0.2] - 2022-05-13
610

711
### Changes & Improvements:

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/Editor/AndroidNotificationPostProcessor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ private void InjectAndroidManifest(string projectPath)
8383
AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.RECEIVE_BOOT_COMPLETED");
8484
}
8585

86+
AppendAndroidPermissionField(manifestPath, manifestDoc, "android.permission.POST_NOTIFICATIONS");
87+
8688
var exactScheduling = GetSetting<AndroidExactSchedulingOption>(settings, NotificationSettings.AndroidSettings.EXACT_ALARM);
8789
bool enableExact = (exactScheduling & AndroidExactSchedulingOption.ExactWhenAvailable) != 0;
8890
AppendAndroidMetadataField(manifestPath, manifestDoc, "com.unity.androidnotifications.exact_scheduling", enableExact ? "1" : "0");

0 commit comments

Comments
 (0)