com.onesignal.unity.ios 5.0.0-beta.2 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Editor/BuildPostProcessor.cs +1 -1
- package/Editor/OneSignaliOSDependencies.xml +1 -1
- package/Editor/PBXProjectExtensions.cs +1 -1
- package/LICENSE.md +1 -1
- package/Runtime/AssemblyInfo.cs +1 -1
- package/Runtime/OneSignaliOS.cs +26 -44
- package/Runtime/OneSignaliOSInit.cs +2 -2
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.h +4 -3
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.mm +20 -10
- package/Runtime/Plugins/iOS/OneSignalUnityBridge.mm +5 -32
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeDebug.mm +1 -1
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeInAppMessages.mm +26 -29
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeLiveActivities.mm +58 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeLiveActivities.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm +1 -1
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm +62 -23
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeSession.mm +1 -1
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeUser.mm +8 -24
- package/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.h +1 -1
- package/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm +1 -1
- package/Runtime/Utilities/WaitingProxy.cs +1 -1
- package/Runtime/iOSDebugManager.cs +1 -1
- package/Runtime/iOSDisplayableNotification.cs +41 -0
- package/Runtime/iOSDisplayableNotification.cs.meta +11 -0
- package/Runtime/iOSInAppMessagesManager.cs +84 -27
- package/Runtime/iOSLiveActivitiesManager.cs +56 -0
- package/Runtime/iOSLiveActivitiesManager.cs.meta +11 -0
- package/Runtime/iOSLocationManager.cs +2 -2
- package/Runtime/iOSNotificationsManager.cs +77 -52
- package/Runtime/iOSPushSubscription.cs +15 -4
- package/Runtime/iOSSessionManager.cs +1 -1
- package/Runtime/iOSUserManager.cs +1 -1
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Modified MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright
|
|
4
|
+
* Copyright 2023 OneSignal
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -32,28 +32,30 @@ using System.Collections.Generic;
|
|
|
32
32
|
using System.Runtime.InteropServices;
|
|
33
33
|
using OneSignalSDK.Notifications;
|
|
34
34
|
using OneSignalSDK.Notifications.Models;
|
|
35
|
+
using OneSignalSDK.Notifications.Internal;
|
|
35
36
|
using OneSignalSDK.iOS.Utilities;
|
|
37
|
+
using OneSignalSDK.iOS.Notifications.Models;
|
|
36
38
|
|
|
37
39
|
namespace OneSignalSDK.iOS.Notifications {
|
|
38
40
|
internal sealed class iOSNotificationsManager : INotificationsManager {
|
|
39
41
|
[DllImport("__Internal")] private static extern bool _notificationsGetPermission();
|
|
40
|
-
|
|
42
|
+
[DllImport("__Internal")] private static extern bool _notificationsGetCanRequestPermission();
|
|
43
|
+
[DllImport("__Internal")] private static extern int _notificationsGetPermissionNative();
|
|
41
44
|
[DllImport("__Internal")] private static extern void _notificationsRequestPermission(bool fallbackToSettings, int hashCode, BooleanResponseDelegate callback);
|
|
42
45
|
[DllImport("__Internal")] private static extern void _notificationsClearAll();
|
|
43
|
-
|
|
44
|
-
[DllImport("__Internal")] private static extern void
|
|
45
|
-
[DllImport("__Internal")] private static extern void
|
|
46
|
-
[DllImport("__Internal")] private static extern void
|
|
47
|
-
|
|
48
|
-
public delegate void
|
|
49
|
-
|
|
50
|
-
private delegate
|
|
51
|
-
private delegate void StringListenerDelegate(string response);
|
|
46
|
+
[DllImport("__Internal")] private static extern void _notificationsAddPermissionObserver(PermissionListenerDelegate callback);
|
|
47
|
+
[DllImport("__Internal")] private static extern void _notificationsSetForegroundWillDisplayCallback(WillDisplayListenerDelegate callback);
|
|
48
|
+
[DllImport("__Internal")] private static extern void _notificationsWillDisplayEventPreventDefault(string notificationId);
|
|
49
|
+
[DllImport("__Internal")] private static extern void _notificationsSetClickCallback(ClickListenerDelegate callback);
|
|
50
|
+
|
|
51
|
+
public delegate void PermissionListenerDelegate(bool permission);
|
|
52
|
+
private delegate void WillDisplayListenerDelegate(string notification);
|
|
53
|
+
private delegate void ClickListenerDelegate(string notification, string resultActionId, string resultUrl);
|
|
52
54
|
private delegate void BooleanResponseDelegate(int hashCode, bool response);
|
|
53
55
|
|
|
54
|
-
public event
|
|
55
|
-
public event
|
|
56
|
-
public event
|
|
56
|
+
public event EventHandler<NotificationWillDisplayEventArgs> ForegroundWillDisplay;
|
|
57
|
+
public event EventHandler<NotificationClickEventArgs> Clicked;
|
|
58
|
+
public event EventHandler<NotificationPermissionChangedEventArgs> PermissionChanged;
|
|
57
59
|
|
|
58
60
|
private static iOSNotificationsManager _instance;
|
|
59
61
|
|
|
@@ -65,6 +67,14 @@ namespace OneSignalSDK.iOS.Notifications {
|
|
|
65
67
|
get => _notificationsGetPermission();
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
public bool CanRequestPermission {
|
|
71
|
+
get => _notificationsGetCanRequestPermission();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public NotificationPermission PermissionNative {
|
|
75
|
+
get => (NotificationPermission)_notificationsGetPermissionNative();
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
public async Task<bool> RequestPermissionAsync(bool fallbackToSettings) {
|
|
69
79
|
var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
|
|
70
80
|
_notificationsRequestPermission(fallbackToSettings, hashCode, BooleanCallbackProxy);
|
|
@@ -76,57 +86,76 @@ namespace OneSignalSDK.iOS.Notifications {
|
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
public void Initialize() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
_notificationsAddPermissionObserver(_onPermissionStateChanged);
|
|
90
|
+
_notificationsSetForegroundWillDisplayCallback(_onForegroundWillDisplay);
|
|
91
|
+
_notificationsSetClickCallback(_onClicked);
|
|
82
92
|
}
|
|
83
93
|
|
|
84
|
-
[AOT.MonoPInvokeCallback(typeof(
|
|
85
|
-
private static void _onPermissionStateChanged(
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
[AOT.MonoPInvokeCallback(typeof(PermissionListenerDelegate))]
|
|
95
|
+
private static void _onPermissionStateChanged(bool permission) {
|
|
96
|
+
NotificationPermissionChangedEventArgs args = new NotificationPermissionChangedEventArgs(permission);
|
|
97
|
+
|
|
98
|
+
EventHandler<NotificationPermissionChangedEventArgs> handler = _instance.PermissionChanged;
|
|
99
|
+
if (handler != null)
|
|
100
|
+
{
|
|
101
|
+
UnityMainThreadDispatch.Post(state => handler(_instance, args));
|
|
102
|
+
}
|
|
88
103
|
}
|
|
89
104
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
105
|
+
[AOT.MonoPInvokeCallback(typeof(WillDisplayListenerDelegate))]
|
|
106
|
+
private static void _onForegroundWillDisplay(string notification) {
|
|
107
|
+
var notif = JsonUtility.FromJson<iOSDisplayableNotification>(notification);
|
|
108
|
+
_fillNotifFromObj(ref notif, Json.Deserialize(notification));
|
|
109
|
+
|
|
110
|
+
InternalNotificationWillDisplayEventArgs args = new InternalNotificationWillDisplayEventArgs(notif);
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
EventHandler<NotificationWillDisplayEventArgs> handler = _instance.ForegroundWillDisplay;
|
|
113
|
+
if (handler != null)
|
|
114
|
+
{
|
|
115
|
+
// We use Send instead of Post because we need to *not* return to our caller until the
|
|
116
|
+
// event handlers have returned themselves. This allows a handler to call PreventDefault()
|
|
117
|
+
// which will get passed down to Android in InternalNotificationWillDisplayEventArgs.
|
|
118
|
+
UnityMainThreadDispatch.Send(state => handler(_instance, args));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
98
121
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
UnityMainThreadDispatch.Send(state => { resultNotif = _instance.WillShow(notification);});
|
|
122
|
+
public class InternalNotificationWillDisplayEventArgs : NotificationWillDisplayEventArgs {
|
|
123
|
+
public InternalNotificationWillDisplayEventArgs(IDisplayableNotification notification) : base(notification) { }
|
|
102
124
|
|
|
103
|
-
|
|
125
|
+
public override void PreventDefault() {
|
|
126
|
+
_notificationsWillDisplayEventPreventDefault(this.Notification.NotificationId);
|
|
127
|
+
}
|
|
104
128
|
}
|
|
105
129
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
130
|
+
[AOT.MonoPInvokeCallback(typeof(ClickListenerDelegate))]
|
|
131
|
+
private static void _onClicked(string notification, string resultActionId, string resultUrl) {
|
|
132
|
+
var notif = JsonUtility.FromJson<iOSDisplayableNotification>(notification);
|
|
133
|
+
_fillNotifFromObj(ref notif, Json.Deserialize(notification));
|
|
134
|
+
|
|
135
|
+
var result = new NotificationClickResult(resultActionId, resultUrl);
|
|
136
|
+
|
|
137
|
+
NotificationClickEventArgs args = new NotificationClickEventArgs(notif, result);
|
|
110
138
|
|
|
111
|
-
|
|
112
|
-
|
|
139
|
+
EventHandler<NotificationClickEventArgs> handler = _instance.Clicked;
|
|
140
|
+
if (handler != null)
|
|
141
|
+
{
|
|
142
|
+
if (OneSignalPlatform.DidInitialize)
|
|
143
|
+
UnityMainThreadDispatch.Post(state => handler(_instance, args));
|
|
144
|
+
else {
|
|
145
|
+
void invokeOpened(string appId) {
|
|
146
|
+
OneSignalPlatform.OnInitialize -= invokeOpened;
|
|
147
|
+
UnityMainThreadDispatch.Post(state => handler(_instance, args));
|
|
148
|
+
}
|
|
113
149
|
|
|
114
|
-
|
|
115
|
-
UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(notifOpenResult));
|
|
116
|
-
else {
|
|
117
|
-
void invokeOpened(string appId) {
|
|
118
|
-
OneSignal.OnInitialize -= invokeOpened;
|
|
119
|
-
UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(notifOpenResult));
|
|
150
|
+
OneSignalPlatform.OnInitialize += invokeOpened;
|
|
120
151
|
}
|
|
121
|
-
|
|
122
|
-
OneSignal.OnInitialize += invokeOpened;
|
|
123
152
|
}
|
|
124
153
|
}
|
|
125
154
|
|
|
126
|
-
private static void _fillNotifFromObj(ref
|
|
155
|
+
private static void _fillNotifFromObj(ref iOSDisplayableNotification notif, object notifObj) {
|
|
127
156
|
if (!(notifObj is Dictionary<string, object> notifDict))
|
|
128
157
|
return;
|
|
129
|
-
|
|
158
|
+
|
|
130
159
|
if (notifDict.ContainsKey("additionalData"))
|
|
131
160
|
notif.additionalData = notifDict["additionalData"] as Dictionary<string, object>;
|
|
132
161
|
|
|
@@ -137,10 +166,6 @@ namespace OneSignalSDK.iOS.Notifications {
|
|
|
137
166
|
notif.rawPayload = Json.Serialize(payloadDict);
|
|
138
167
|
}
|
|
139
168
|
|
|
140
|
-
[Serializable] private sealed class PermissionState { // temp
|
|
141
|
-
public bool permission;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
169
|
[AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
|
|
145
170
|
private static void BooleanCallbackProxy(int hashCode, bool response)
|
|
146
171
|
=> WaitingProxy.ResolveCallbackProxy(hashCode, response);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* Modified MIT License
|
|
3
3
|
*
|
|
4
|
-
* Copyright
|
|
4
|
+
* Copyright 2023 OneSignal
|
|
5
5
|
*
|
|
6
6
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
7
|
* of this software and associated documentation files (the "Software"), to deal
|
|
@@ -29,6 +29,9 @@ using System;
|
|
|
29
29
|
using UnityEngine;
|
|
30
30
|
using System.Runtime.InteropServices;
|
|
31
31
|
using OneSignalSDK.User.Models;
|
|
32
|
+
using OneSignalSDK.User.Internal;
|
|
33
|
+
|
|
34
|
+
using OneSignalSDK.Debug.Utilities;
|
|
32
35
|
|
|
33
36
|
namespace OneSignalSDK.iOS.User.Models {
|
|
34
37
|
internal sealed class iOSPushSubscription : IPushSubscription {
|
|
@@ -41,7 +44,7 @@ namespace OneSignalSDK.iOS.User.Models {
|
|
|
41
44
|
|
|
42
45
|
public delegate void StateListenerDelegate(string current, string previous);
|
|
43
46
|
|
|
44
|
-
public event
|
|
47
|
+
public event EventHandler<PushSubscriptionChangedEventArgs> Changed;
|
|
45
48
|
|
|
46
49
|
private static iOSPushSubscription _instance;
|
|
47
50
|
|
|
@@ -74,8 +77,16 @@ namespace OneSignalSDK.iOS.User.Models {
|
|
|
74
77
|
[AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
|
|
75
78
|
private static void _onPushSubscriptionStateChanged(string current, string previous) {
|
|
76
79
|
var curr = JsonUtility.FromJson<PushSubscriptionState>(current);
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
var prev = JsonUtility.FromJson<PushSubscriptionState>(previous);
|
|
81
|
+
|
|
82
|
+
PushSubscriptionChangedState state = new PushSubscriptionChangedState(prev, curr);
|
|
83
|
+
PushSubscriptionChangedEventArgs args = new PushSubscriptionChangedEventArgs(state);
|
|
84
|
+
|
|
85
|
+
EventHandler<PushSubscriptionChangedEventArgs> handler = _instance.Changed;
|
|
86
|
+
if (handler != null)
|
|
87
|
+
{
|
|
88
|
+
UnityMainThreadDispatch.Post(state => handler(_instance, args));
|
|
89
|
+
}
|
|
79
90
|
}
|
|
80
91
|
}
|
|
81
92
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "com.onesignal.unity.ios",
|
|
3
3
|
"displayName": "OneSignal Unity SDK - iOS",
|
|
4
|
-
"version": "5.0.0
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"unity": "2018.4",
|
|
6
6
|
"description": "OneSignal is the market leader in customer engagement, powering mobile push, web push, email, and in-app messages.",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"com.onesignal.unity.core": "5.0.0
|
|
8
|
+
"com.onesignal.unity.core": "5.0.0"
|
|
9
9
|
},
|
|
10
10
|
"keywords": [
|
|
11
11
|
"push-notifications",
|