com.onesignal.unity.ios 3.0.8 → 5.0.0-beta.1
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 +4 -2
- package/Editor/OneSignaliOSDependencies.xml +5 -0
- package/Editor/OneSignaliOSDependencies.xml.meta +7 -0
- package/Editor/PBXProjectExtensions.cs +1 -1
- package/Runtime/OneSignaliOS.cs +178 -0
- package/Runtime/OneSignaliOS.cs.meta +11 -0
- package/Runtime/{OneSignalIOSInit.cs → OneSignaliOSInit.cs} +3 -3
- package/Runtime/OneSignaliOSInit.cs.meta +11 -0
- package/Runtime/Plugins/iOS/NotificationService.swift +1 -1
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.h +35 -0
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.h.meta +27 -0
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.mm +49 -0
- package/Runtime/Plugins/iOS/OneSignalBridgeUtil.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridge.mm +36 -383
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeDebug.mm +40 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeDebug.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeInAppMessages.mm +167 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeInAppMessages.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm +44 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeLocation.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm +124 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeNotifications.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeSession.mm +55 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeSession.mm.meta +37 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeUser.mm +197 -0
- package/Runtime/Plugins/iOS/OneSignalUnityBridgeUser.mm.meta +37 -0
- package/Runtime/Plugins/iOS/UIApplication+OneSignalUnity.mm +4 -2
- package/Runtime/Utilities/WaitingProxy.cs +52 -0
- package/Runtime/Utilities/WaitingProxy.cs.meta +11 -0
- package/Runtime/iOSDebugManager.cs +57 -0
- package/Runtime/iOSDebugManager.cs.meta +11 -0
- package/Runtime/iOSInAppMessagesManager.cs +118 -0
- package/Runtime/iOSInAppMessagesManager.cs.meta +11 -0
- package/Runtime/iOSLocationManager.cs +48 -0
- package/Runtime/iOSLocationManager.cs.meta +11 -0
- package/Runtime/iOSNotificationsManager.cs +148 -0
- package/Runtime/iOSNotificationsManager.cs.meta +11 -0
- package/Runtime/iOSPushSubscription.cs +81 -0
- package/Runtime/iOSPushSubscription.cs.meta +11 -0
- package/Runtime/iOSSessionManager.cs +47 -0
- package/Runtime/iOSSessionManager.cs.meta +11 -0
- package/Runtime/iOSUserManager.cs +106 -0
- package/Runtime/iOSUserManager.cs.meta +11 -0
- package/package.json +2 -2
- package/Editor/OneSignalIOSDependencies.xml +0 -5
- package/Editor/OneSignalIOSDependencies.xml.meta +0 -3
- package/Runtime/OneSignalIOS.Callbacks.cs +0 -181
- package/Runtime/OneSignalIOS.Callbacks.cs.meta +0 -3
- package/Runtime/OneSignalIOS.Interface.cs +0 -102
- package/Runtime/OneSignalIOS.Interface.cs.meta +0 -3
- package/Runtime/OneSignalIOS.Mappings.cs +0 -96
- package/Runtime/OneSignalIOS.Mappings.cs.meta +0 -3
- package/Runtime/OneSignalIOS.cs +0 -257
- package/Runtime/OneSignalIOS.cs.meta +0 -3
- package/Runtime/OneSignalIOSInit.cs.meta +0 -3
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
using UnityEngine;
|
|
29
|
+
using System.Runtime.InteropServices;
|
|
30
|
+
using OneSignalSDK.Debug;
|
|
31
|
+
using OneSignalSDK.Debug.Models;
|
|
32
|
+
|
|
33
|
+
namespace OneSignalSDK.iOS.Debug {
|
|
34
|
+
internal sealed class iOSDebugManager : IDebugManager {
|
|
35
|
+
[DllImport("__Internal")] private static extern void _debugSetLogLevel(int logLevel);
|
|
36
|
+
[DllImport("__Internal")] private static extern void _debugSetAlertLevel(int alertlLevel);
|
|
37
|
+
|
|
38
|
+
private LogLevel _logLevel = LogLevel.Warn;
|
|
39
|
+
private LogLevel _alertLevel = LogLevel.None;
|
|
40
|
+
|
|
41
|
+
public LogLevel LogLevel {
|
|
42
|
+
get => _logLevel;
|
|
43
|
+
set {
|
|
44
|
+
_logLevel = value;
|
|
45
|
+
_debugSetLogLevel((int) value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public LogLevel AlertLevel {
|
|
50
|
+
get => _alertLevel;
|
|
51
|
+
set {
|
|
52
|
+
_alertLevel = value;
|
|
53
|
+
_debugSetAlertLevel((int) value);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
using UnityEngine;
|
|
30
|
+
using System.Collections.Generic;
|
|
31
|
+
using System.Runtime.InteropServices;
|
|
32
|
+
using OneSignalSDK.InAppMessages;
|
|
33
|
+
using OneSignalSDK.InAppMessages.Models;
|
|
34
|
+
|
|
35
|
+
namespace OneSignalSDK.iOS.InAppMessages {
|
|
36
|
+
internal sealed class iOSInAppMessagesManager : IInAppMessagesManager {
|
|
37
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetWillDisplayCallback(StringListenerDelegate callback);
|
|
38
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetDidDisplayCallback(StringListenerDelegate callback);
|
|
39
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetWillDismissCallback(StringListenerDelegate callback);
|
|
40
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetDidDismissCallback(StringListenerDelegate callback);
|
|
41
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetClickedCallback(StringListenerDelegate callback);
|
|
42
|
+
|
|
43
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesSetPaused(bool paused);
|
|
44
|
+
[DllImport("__Internal")] private static extern bool _inAppMessagesGetPaused();
|
|
45
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesAddTrigger(string key, string value);
|
|
46
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesAddTriggers(string triggersJson);
|
|
47
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesRemoveTrigger(string key);
|
|
48
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesRemoveTriggers(string triggersJson);
|
|
49
|
+
[DllImport("__Internal")] private static extern void _inAppMessagesClearTriggers();
|
|
50
|
+
|
|
51
|
+
private delegate void StringListenerDelegate(string response);
|
|
52
|
+
|
|
53
|
+
public event InAppMessageLifecycleDelegate WillDisplay;
|
|
54
|
+
public event InAppMessageLifecycleDelegate DidDisplay;
|
|
55
|
+
public event InAppMessageLifecycleDelegate WillDismiss;
|
|
56
|
+
public event InAppMessageLifecycleDelegate DidDismiss;
|
|
57
|
+
|
|
58
|
+
public event InAppMessageClickedDelegate Clicked;
|
|
59
|
+
|
|
60
|
+
private static iOSInAppMessagesManager _instance;
|
|
61
|
+
|
|
62
|
+
public iOSInAppMessagesManager() {
|
|
63
|
+
_instance = this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public bool Paused {
|
|
67
|
+
get => _inAppMessagesGetPaused();
|
|
68
|
+
set => _inAppMessagesSetPaused(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public void AddTrigger(string key, object value)
|
|
72
|
+
=> _inAppMessagesAddTrigger(key, value.ToString()); // test
|
|
73
|
+
|
|
74
|
+
public void AddTriggers(Dictionary<string, object> triggers) // <string, string> to <string, object>
|
|
75
|
+
=> _inAppMessagesAddTriggers(Json.Serialize(triggers));
|
|
76
|
+
|
|
77
|
+
public void RemoveTrigger(string key)
|
|
78
|
+
=> _inAppMessagesRemoveTrigger(key);
|
|
79
|
+
|
|
80
|
+
public void RemoveTriggers(params string[] keys)
|
|
81
|
+
=> _inAppMessagesRemoveTriggers(Json.Serialize(keys));
|
|
82
|
+
|
|
83
|
+
public void ClearTriggers()
|
|
84
|
+
=> _inAppMessagesClearTriggers();
|
|
85
|
+
|
|
86
|
+
public void Initialize() {
|
|
87
|
+
_inAppMessagesSetWillDisplayCallback(_onWillDisplay);
|
|
88
|
+
_inAppMessagesSetDidDisplayCallback(_onDidDisplay);
|
|
89
|
+
_inAppMessagesSetWillDismissCallback(_onWillDismiss);
|
|
90
|
+
_inAppMessagesSetDidDismissCallback(_onDidDismiss);
|
|
91
|
+
_inAppMessagesSetClickedCallback(_onClicked);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
|
|
95
|
+
private static void _onWillDisplay(string response)
|
|
96
|
+
=> UnityMainThreadDispatch.Post(state => _instance.WillDisplay?.Invoke(new InAppMessage { messageId = response }));
|
|
97
|
+
|
|
98
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
|
|
99
|
+
private static void _onDidDisplay(string response)
|
|
100
|
+
=> UnityMainThreadDispatch.Post(state => _instance.DidDisplay?.Invoke(new InAppMessage { messageId = response }));
|
|
101
|
+
|
|
102
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
|
|
103
|
+
private static void _onWillDismiss(string response)
|
|
104
|
+
=> UnityMainThreadDispatch.Post(state => _instance.WillDismiss?.Invoke(new InAppMessage { messageId = response }));
|
|
105
|
+
|
|
106
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
|
|
107
|
+
private static void _onDidDismiss(string response)
|
|
108
|
+
=> UnityMainThreadDispatch.Post(state => _instance.DidDismiss?.Invoke(new InAppMessage { messageId = response }));
|
|
109
|
+
|
|
110
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))] // iOS returns InAppMessageAction. Android returns InAppMessageClickedResult
|
|
111
|
+
private static void _onClicked(string response) {
|
|
112
|
+
InAppMessageClickedResult temp = new InAppMessageClickedResult();
|
|
113
|
+
temp.action = JsonUtility.FromJson<InAppMessageAction>(response);
|
|
114
|
+
//temp.message = new InAppMessage { messageId = "messageIdTemp" };
|
|
115
|
+
UnityMainThreadDispatch.Post(state => _instance.Clicked?.Invoke(temp));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
using UnityEngine;
|
|
29
|
+
using System.Threading.Tasks;
|
|
30
|
+
using OneSignalSDK.Location;
|
|
31
|
+
using System.Runtime.InteropServices;
|
|
32
|
+
|
|
33
|
+
namespace OneSignalSDK.iOS.Location {
|
|
34
|
+
internal sealed class iOSLocationManager : ILocationManager {
|
|
35
|
+
[DllImport("__Internal")] private static extern bool _locationGetIsShared();
|
|
36
|
+
[DllImport("__Internal")] private static extern void _locationSetIsShared(bool shared);
|
|
37
|
+
[DllImport("__Internal")] private static extern void _locationRequestPermission();
|
|
38
|
+
|
|
39
|
+
public bool IsShared {
|
|
40
|
+
get => _locationGetIsShared();
|
|
41
|
+
set => _locationSetIsShared(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public void RequestPermission() { // iOS make async
|
|
45
|
+
_locationRequestPermission();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
using System;
|
|
29
|
+
using UnityEngine;
|
|
30
|
+
using System.Threading.Tasks;
|
|
31
|
+
using System.Collections.Generic;
|
|
32
|
+
using System.Runtime.InteropServices;
|
|
33
|
+
using OneSignalSDK.Notifications;
|
|
34
|
+
using OneSignalSDK.Notifications.Models;
|
|
35
|
+
using OneSignalSDK.iOS.Utilities;
|
|
36
|
+
|
|
37
|
+
namespace OneSignalSDK.iOS.Notifications {
|
|
38
|
+
internal sealed class iOSNotificationsManager : INotificationsManager {
|
|
39
|
+
[DllImport("__Internal")] private static extern bool _notificationsGetPermission();
|
|
40
|
+
//[DllImport("__Internal")] private static extern bool _notificationsGetCanRequestPermission(); // iOS only for now
|
|
41
|
+
[DllImport("__Internal")] private static extern void _notificationsRequestPermission(bool fallbackToSettings, int hashCode, BooleanResponseDelegate callback);
|
|
42
|
+
[DllImport("__Internal")] private static extern void _notificationsClearAll();
|
|
43
|
+
//[DllImport("__Internal")] private static extern void _registerForProvisionalAuthorization(); // iOS only
|
|
44
|
+
[DllImport("__Internal")] private static extern void _notificationsAddPermissionStateChangedCallback(StateListenerDelegate callback);
|
|
45
|
+
[DllImport("__Internal")] private static extern void _notificationsSetWillShowHandler(NotificationWillShowInForegroundDelegate callback);
|
|
46
|
+
[DllImport("__Internal")] private static extern void _notificationsSetOpenedHandler(StringListenerDelegate callback);
|
|
47
|
+
|
|
48
|
+
public delegate void StateListenerDelegate(string current);
|
|
49
|
+
|
|
50
|
+
private delegate bool NotificationWillShowInForegroundDelegate(string notification);
|
|
51
|
+
private delegate void StringListenerDelegate(string response);
|
|
52
|
+
private delegate void BooleanResponseDelegate(int hashCode, bool response);
|
|
53
|
+
|
|
54
|
+
public event NotificationWillShowDelegate WillShow;
|
|
55
|
+
public event NotificationClickedDelegate Clicked;
|
|
56
|
+
public event PermissionChangedDelegate PermissionChanged;
|
|
57
|
+
|
|
58
|
+
private static iOSNotificationsManager _instance;
|
|
59
|
+
|
|
60
|
+
public iOSNotificationsManager() {
|
|
61
|
+
_instance = this;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public bool Permission {
|
|
65
|
+
get => _notificationsGetPermission();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public async Task<bool> RequestPermissionAsync(bool fallbackToSettings) {
|
|
69
|
+
var (proxy, hashCode) = WaitingProxy._setupProxy<bool>();
|
|
70
|
+
_notificationsRequestPermission(fallbackToSettings, hashCode, BooleanCallbackProxy);
|
|
71
|
+
return await proxy;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public void ClearAllNotifications() {
|
|
75
|
+
_notificationsClearAll();
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public void Initialize() {
|
|
79
|
+
_notificationsAddPermissionStateChangedCallback(_onPermissionStateChanged);
|
|
80
|
+
_notificationsSetWillShowHandler(_onWillShow);
|
|
81
|
+
_notificationsSetOpenedHandler(_onOpened);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
[AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
|
|
85
|
+
private static void _onPermissionStateChanged(string current) {
|
|
86
|
+
var curr = JsonUtility.FromJson<PermissionState>(current);
|
|
87
|
+
UnityMainThreadDispatch.Post(state => _instance.PermissionChanged?.Invoke(curr.permission));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// <param name="response">OSNotification</param>
|
|
91
|
+
[AOT.MonoPInvokeCallback(typeof(NotificationWillShowInForegroundDelegate))]
|
|
92
|
+
private static bool _onWillShow(string response) {
|
|
93
|
+
if (_instance.WillShow == null)
|
|
94
|
+
return true;
|
|
95
|
+
|
|
96
|
+
var notification = JsonUtility.FromJson<Notification>(response);
|
|
97
|
+
_fillNotifFromObj(ref notification, Json.Deserialize(response));
|
|
98
|
+
|
|
99
|
+
Notification resultNotif = null;
|
|
100
|
+
// Blocks current thread using Send to wait for value to assign to resultNotif inorder to display
|
|
101
|
+
UnityMainThreadDispatch.Send(state => { resultNotif = _instance.WillShow(notification);});
|
|
102
|
+
|
|
103
|
+
return resultNotif != null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/// <param name="response">OSNotificationOpenedResult</param>
|
|
107
|
+
[AOT.MonoPInvokeCallback(typeof(StringListenerDelegate))]
|
|
108
|
+
private static void _onOpened(string response) {
|
|
109
|
+
var notifOpenResult = JsonUtility.FromJson<NotificationClickedResult>(response);
|
|
110
|
+
|
|
111
|
+
if (Json.Deserialize(response) is Dictionary<string, object> resultDict && resultDict.ContainsKey("notification"))
|
|
112
|
+
_fillNotifFromObj(ref notifOpenResult.notification, resultDict["notification"]);
|
|
113
|
+
|
|
114
|
+
if (OneSignal.DidInitialize)
|
|
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));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
OneSignal.OnInitialize += invokeOpened;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private static void _fillNotifFromObj(ref Notification notif, object notifObj) {
|
|
127
|
+
if (!(notifObj is Dictionary<string, object> notifDict))
|
|
128
|
+
return;
|
|
129
|
+
|
|
130
|
+
if (notifDict.ContainsKey("additionalData"))
|
|
131
|
+
notif.additionalData = notifDict["additionalData"] as Dictionary<string, object>;
|
|
132
|
+
|
|
133
|
+
if (notifDict.ContainsKey("attachments"))
|
|
134
|
+
notif.attachments = notifDict["attachments"] as Dictionary<string, object>;
|
|
135
|
+
|
|
136
|
+
if (notifDict.ContainsKey("rawPayload") && notifDict["rawPayload"] is Dictionary<string, object> payloadDict)
|
|
137
|
+
notif.rawPayload = Json.Serialize(payloadDict);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
[Serializable] private sealed class PermissionState { // temp
|
|
141
|
+
public bool permission;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
[AOT.MonoPInvokeCallback(typeof(BooleanResponseDelegate))]
|
|
145
|
+
private static void BooleanCallbackProxy(int hashCode, bool response)
|
|
146
|
+
=> WaitingProxy.ResolveCallbackProxy(hashCode, response);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
using System;
|
|
29
|
+
using UnityEngine;
|
|
30
|
+
using System.Runtime.InteropServices;
|
|
31
|
+
using OneSignalSDK.User.Models;
|
|
32
|
+
|
|
33
|
+
namespace OneSignalSDK.iOS.User.Models {
|
|
34
|
+
internal sealed class iOSPushSubscription : IPushSubscription {
|
|
35
|
+
[DllImport("__Internal")] private static extern string _pushSubscriptionGetId();
|
|
36
|
+
[DllImport("__Internal")] private static extern string _pushSubscriptionGetToken();
|
|
37
|
+
[DllImport("__Internal")] private static extern bool _pushSubscriptionGetOptedIn();
|
|
38
|
+
[DllImport("__Internal")] private static extern void _pushSubscriptionOptIn();
|
|
39
|
+
[DllImport("__Internal")] private static extern void _pushSubscriptionOptOut();
|
|
40
|
+
[DllImport("__Internal")] private static extern void _pushSubscriptionAddStateChangedCallback(StateListenerDelegate callback);
|
|
41
|
+
|
|
42
|
+
public delegate void StateListenerDelegate(string current, string previous);
|
|
43
|
+
|
|
44
|
+
public event SubscriptionChangedDelegate Changed;
|
|
45
|
+
|
|
46
|
+
private static iOSPushSubscription _instance;
|
|
47
|
+
|
|
48
|
+
public iOSPushSubscription() {
|
|
49
|
+
_instance = this;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public string Id {
|
|
53
|
+
get => _pushSubscriptionGetId();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public string Token {
|
|
57
|
+
get => _pushSubscriptionGetToken();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public bool OptedIn {
|
|
61
|
+
get => _pushSubscriptionGetOptedIn();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public void OptIn()
|
|
65
|
+
=> _pushSubscriptionOptIn();
|
|
66
|
+
|
|
67
|
+
public void OptOut()
|
|
68
|
+
=> _pushSubscriptionOptOut();
|
|
69
|
+
|
|
70
|
+
public void Initialize() {
|
|
71
|
+
_pushSubscriptionAddStateChangedCallback(_onPushSubscriptionStateChanged);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[AOT.MonoPInvokeCallback(typeof(StateListenerDelegate))]
|
|
75
|
+
private static void _onPushSubscriptionStateChanged(string current, string previous) {
|
|
76
|
+
var curr = JsonUtility.FromJson<PushSubscriptionState>(current);
|
|
77
|
+
//var prev = JsonUtility.FromJson<PushSubscriptionState>(previous);
|
|
78
|
+
UnityMainThreadDispatch.Post(state => _instance.Changed?.Invoke(curr));
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Modified MIT License
|
|
3
|
+
*
|
|
4
|
+
* Copyright 2022 OneSignal
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* 1. The above copyright notice and this permission notice shall be included in
|
|
14
|
+
* all copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* 2. All copies of substantial portions of the Software may only be used in connection
|
|
17
|
+
* with services provided by OneSignal.
|
|
18
|
+
*
|
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
25
|
+
* THE SOFTWARE.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
using UnityEngine;
|
|
29
|
+
using OneSignalSDK.Session;
|
|
30
|
+
using System.Runtime.InteropServices;
|
|
31
|
+
|
|
32
|
+
namespace OneSignalSDK.iOS.Session {
|
|
33
|
+
internal sealed class iOSSessionManager : ISessionManager {
|
|
34
|
+
[DllImport("__Internal")] private static extern void _sessionAddOutcome(string name);
|
|
35
|
+
[DllImport("__Internal")] private static extern void _sessionAddUniqueOutcome(string name);
|
|
36
|
+
[DllImport("__Internal")] private static extern void _sessionAddOutcomeWithValue(string name, float value);
|
|
37
|
+
|
|
38
|
+
public void AddOutcome(string name)
|
|
39
|
+
=> _sessionAddOutcome(name);
|
|
40
|
+
|
|
41
|
+
public void AddUniqueOutcome(string name)
|
|
42
|
+
=> _sessionAddUniqueOutcome(name);
|
|
43
|
+
|
|
44
|
+
public void AddOutcomeWithValue(string name, float value)
|
|
45
|
+
=> _sessionAddOutcomeWithValue(name, value);
|
|
46
|
+
}
|
|
47
|
+
}
|