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 . Collections . Generic ;
29
+ using System . Linq ;
30
+ using System . Threading . Tasks ;
31
+ using UnityEngine ;
32
+ using System . Runtime . InteropServices ;
33
+ using OneSignalSDKNew . iOS . Notifications ;
34
+ using OneSignalSDKNew . iOS . InAppMessages ;
35
+ using OneSignalSDKNew . iOS . Debug ;
36
+ using OneSignalSDKNew . iOS . Location ;
37
+ using OneSignalSDKNew . iOS . Session ;
38
+ using OneSignalSDKNew . iOS . User ;
39
+ using OneSignalSDKNew . iOS . Utilities ;
40
+ using OneSignalSDKNew . Notifications ;
41
+ using OneSignalSDKNew . InAppMessages ;
42
+ using OneSignalSDKNew . Debug ;
43
+ using OneSignalSDKNew . Debug . Utilities ;
44
+ using OneSignalSDKNew . Location ;
45
+ using OneSignalSDKNew . Session ;
46
+ using OneSignalSDKNew . User ;
47
+
48
+ namespace OneSignalSDKNew . iOS {
49
+ public sealed partial class OneSignaliOS : OneSignal {
50
+ [ DllImport ( "__Internal" ) ] private static extern bool _getPrivacyConsent ( ) ;
51
+ [ DllImport ( "__Internal" ) ] private static extern void _setPrivacyConsent ( bool consent ) ;
52
+ [ DllImport ( "__Internal" ) ] private static extern bool _getRequiresPrivacyConsent ( ) ;
53
+ [ DllImport ( "__Internal" ) ] private static extern void _setRequiresPrivacyConsent ( bool required ) ;
54
+ [ DllImport ( "__Internal" ) ] private static extern void _setLaunchURLsInApp ( bool launchInApp ) ;
55
+ [ DllImport ( "__Internal" ) ] private static extern void _initialize ( string appId ) ;
56
+ [ DllImport ( "__Internal" ) ] private static extern void _login ( string externalId ) ;
57
+ [ DllImport ( "__Internal" ) ] private static extern void _logout ( ) ;
58
+ [ DllImport ( "__Internal" ) ] private static extern void _enterLiveActivity ( string activityId , string token , int hashCode , BooleanResponseDelegate callback ) ;
59
+ [ DllImport ( "__Internal" ) ] private static extern void _exitLiveActivity ( string activityId , int hashCode , BooleanResponseDelegate callback ) ;
60
+
61
+ private delegate void BooleanResponseDelegate ( int hashCode , bool response ) ;
62
+
63
+ private iOSUserManager _user ;
64
+ private iOSSessionManager _session ;
65
+ private iOSNotificationsManager _notifications ;
66
+ private iOSLocationManager _location ;
67
+ private iOSInAppMessagesManager _inAppMessages ;
68
+ private iOSDebugManager _debug ;
69
+
70
+ private static OneSignaliOS _instance ;
71
+
72
+ /// <summary>
73
+ /// Used to provide a reference for and sets up the global callbacks
74
+ /// </summary>
75
+ public OneSignaliOS ( ) {
76
+ if ( _instance != null )
77
+ SDKDebug . Error ( "Additional instance of OneSignaliOS created." ) ;
78
+
79
+ _instance = this ;
80
+ _debug = new iOSDebugManager ( ) ;
81
+ }
82
+
83
+ public override IUserManager User {
84
+ get => _user ;
85
+ }
86
+
87
+ public override ISessionManager Session {
88
+ get => _session ;
89
+ }
90
+
91
+ public override INotificationsManager Notifications {
92
+ get => _notifications ;
93
+ }
94
+
95
+ public override ILocationManager Location {
96
+ get => _location ;
97
+ }
98
+
99
+ public override IInAppMessagesManager InAppMessages {
100
+ get => _inAppMessages ;
101
+ }
102
+
103
+ public override IDebugManager Debug {
104
+ get => _debug ;
105
+ }
106
+
107
+ public override bool PrivacyConsent {
108
+ get => _getPrivacyConsent ( ) ;
109
+ set => _setPrivacyConsent ( value ) ;
110
+ }
111
+
112
+ public override bool RequiresPrivacyConsent {
113
+ get => _getRequiresPrivacyConsent ( ) ;
114
+ set => _setRequiresPrivacyConsent ( value ) ;
115
+ }
116
+
117
+ public override void SetLaunchURLsInApp ( bool launchInApp )
118
+ => _setLaunchURLsInApp ( launchInApp ) ;
119
+
120
+ public override void Initialize ( string appId ) {
121
+ _initialize ( appId ) ;
122
+
123
+ if ( _inAppMessages == null ) {
124
+ _inAppMessages = new iOSInAppMessagesManager ( ) ;
125
+ _inAppMessages . Initialize ( ) ;
126
+ }
127
+
128
+ if ( _notifications == null ) {
129
+ _notifications = new iOSNotificationsManager ( ) ;
130
+ _notifications . Initialize ( ) ;
131
+ }
132
+
133
+ if ( _user == null ) {
134
+ _user = new iOSUserManager ( ) ;
135
+ _user . Initialize ( ) ;
136
+ }
137
+
138
+ if ( _location == null ) {
139
+ _location = new iOSLocationManager ( ) ;
140
+ }
141
+
142
+ if ( _session == null ) {
143
+ _session = new iOSSessionManager ( ) ;
144
+ }
145
+
146
+ _completedInit ( appId ) ;
147
+ }
148
+
149
+ public override void Login ( string externalId , string jwtBearerToken = null ) {
150
+ _login ( externalId ) ;
151
+ }
152
+
153
+ public override void Logout ( ) {
154
+ _logout ( ) ;
155
+ }
156
+
157
+ public override async Task < bool > EnterLiveActivity ( string activityId , string token ) {
158
+ var ( proxy , hashCode ) = WaitingProxy . _setupProxy < bool > ( ) ;
159
+ _enterLiveActivity ( activityId , token , hashCode , BooleanCallbackProxy ) ;
160
+ return await proxy ;
161
+ }
162
+
163
+ public override async Task < bool > ExitLiveActivity ( string activityId ) {
164
+ var ( proxy , hashCode ) = WaitingProxy . _setupProxy < bool > ( ) ;
165
+ _exitLiveActivity ( activityId , hashCode , BooleanCallbackProxy ) ;
166
+ return await proxy ;
167
+ }
168
+
169
+ [ AOT . MonoPInvokeCallback ( typeof ( BooleanResponseDelegate ) ) ]
170
+ private static void BooleanCallbackProxy ( int hashCode , bool response )
171
+ => WaitingProxy . ResolveCallbackProxy ( hashCode , response ) ;
172
+ }
173
+ }
0 commit comments