cordova-plugin-pushizo 0.1.0 → 0.2.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/LICENSE +21 -21
- package/README.md +402 -350
- package/package.json +54 -54
- package/plugin.xml +96 -96
- package/src/android/com/pushizo/cordova/PushizoBridgeCore.kt +610 -493
- package/src/android/com/pushizo/cordova/PushizoConfigStore.kt +41 -41
- package/src/android/com/pushizo/cordova/PushizoCordovaPlugin.kt +141 -141
- package/src/android/com/pushizo/cordova/PushizoInitProvider.kt +34 -34
- package/src/android/pushizo.gradle +6 -6
- package/src/ios/PushizoAppDelegateHook.swift +54 -54
- package/src/ios/PushizoBridgeCore.swift +600 -465
- package/src/ios/PushizoCordovaPlugin.swift +166 -157
- package/types/index.d.ts +64 -54
- package/www/core.d.ts +38 -6
- package/www/core.js +66 -5
- package/www/definitions.d.ts +120 -0
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
package com.pushizo.cordova
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import com.pushizo.sdk.Pushizo
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* JS `initialize` ayarlarını saklar. Süreç bildirim tıklaması veya FCM servisi ile yeniden başladığında
|
|
8
|
-
* SDK, WebView yüklenmeden önce bu ayarlarla başlatılır (soğuk başlatma tıklaması ve `received` kaybolmaz).
|
|
9
|
-
* Yalnızca uygulama kimliği ve herkese açık ayarlar tutulur; gizli bilgi yoktur.
|
|
10
|
-
*/
|
|
11
|
-
internal object PushizoConfigStore {
|
|
12
|
-
private const val PREFS = "pushizo_cordova"
|
|
13
|
-
|
|
14
|
-
data class Config(val appId: String, val apiUrl: String, val requiresPrivacyConsent: Boolean, val logLevel: String) {
|
|
15
|
-
fun toOptions() = Pushizo.Options(
|
|
16
|
-
apiUrl = apiUrl,
|
|
17
|
-
requiresPrivacyConsent = requiresPrivacyConsent,
|
|
18
|
-
logLevel = PushizoBridgeCore.logLevel(logLevel),
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
fun save(context: Context, config: Config) {
|
|
23
|
-
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
|
24
|
-
.putString("app_id", config.appId)
|
|
25
|
-
.putString("api_url", config.apiUrl)
|
|
26
|
-
.putBoolean("requires_privacy_consent", config.requiresPrivacyConsent)
|
|
27
|
-
.putString("log_level", config.logLevel)
|
|
28
|
-
.apply()
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
fun load(context: Context): Config? {
|
|
32
|
-
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
|
33
|
-
val appId = prefs.getString("app_id", null)?.takeIf { it.isNotBlank() } ?: return null
|
|
34
|
-
return Config(
|
|
35
|
-
appId = appId,
|
|
36
|
-
apiUrl = prefs.getString("api_url", null) ?: Pushizo.Options().apiUrl,
|
|
37
|
-
requiresPrivacyConsent = prefs.getBoolean("requires_privacy_consent", false),
|
|
38
|
-
logLevel = prefs.getString("log_level", null) ?: "warn",
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
package com.pushizo.cordova
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import com.pushizo.sdk.Pushizo
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* JS `initialize` ayarlarını saklar. Süreç bildirim tıklaması veya FCM servisi ile yeniden başladığında
|
|
8
|
+
* SDK, WebView yüklenmeden önce bu ayarlarla başlatılır (soğuk başlatma tıklaması ve `received` kaybolmaz).
|
|
9
|
+
* Yalnızca uygulama kimliği ve herkese açık ayarlar tutulur; gizli bilgi yoktur.
|
|
10
|
+
*/
|
|
11
|
+
internal object PushizoConfigStore {
|
|
12
|
+
private const val PREFS = "pushizo_cordova"
|
|
13
|
+
|
|
14
|
+
data class Config(val appId: String, val apiUrl: String, val requiresPrivacyConsent: Boolean, val logLevel: String) {
|
|
15
|
+
fun toOptions() = Pushizo.Options(
|
|
16
|
+
apiUrl = apiUrl,
|
|
17
|
+
requiresPrivacyConsent = requiresPrivacyConsent,
|
|
18
|
+
logLevel = PushizoBridgeCore.logLevel(logLevel),
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
fun save(context: Context, config: Config) {
|
|
23
|
+
context.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit()
|
|
24
|
+
.putString("app_id", config.appId)
|
|
25
|
+
.putString("api_url", config.apiUrl)
|
|
26
|
+
.putBoolean("requires_privacy_consent", config.requiresPrivacyConsent)
|
|
27
|
+
.putString("log_level", config.logLevel)
|
|
28
|
+
.apply()
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fun load(context: Context): Config? {
|
|
32
|
+
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
|
33
|
+
val appId = prefs.getString("app_id", null)?.takeIf { it.isNotBlank() } ?: return null
|
|
34
|
+
return Config(
|
|
35
|
+
appId = appId,
|
|
36
|
+
apiUrl = prefs.getString("api_url", null) ?: Pushizo.Options().apiUrl,
|
|
37
|
+
requiresPrivacyConsent = prefs.getBoolean("requires_privacy_consent", false),
|
|
38
|
+
logLevel = prefs.getString("log_level", null) ?: "warn",
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,141 +1,141 @@
|
|
|
1
|
-
package com.pushizo.cordova
|
|
2
|
-
|
|
3
|
-
import android.Manifest
|
|
4
|
-
import android.os.Build
|
|
5
|
-
import com.pushizo.sdk.Pushizo
|
|
6
|
-
import org.apache.cordova.CallbackContext
|
|
7
|
-
import org.apache.cordova.CordovaPlugin
|
|
8
|
-
import org.apache.cordova.PluginResult
|
|
9
|
-
import org.json.JSONArray
|
|
10
|
-
import org.json.JSONObject
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Cordova → Pushizo Android SDK köprüsü (`cordova.exec` servisi "Pushizo"). Metotlar
|
|
14
|
-
* [PushizoBridgeCore] üzerinden SDK'ya iletilir. SDK olayları JS'in `setEventCallback` ile açtığı tek
|
|
15
|
-
* `keepCallback` kanalından `{ type, payload }` olarak gönderilir; kanal açılmadan gelen olaylar tamponlanır.
|
|
16
|
-
*/
|
|
17
|
-
class PushizoCordovaPlugin : CordovaPlugin() {
|
|
18
|
-
private lateinit var core: PushizoBridgeCore
|
|
19
|
-
private val lock = Any()
|
|
20
|
-
private var eventCallback: CallbackContext? = null
|
|
21
|
-
private val bufferedEvents = ArrayDeque<JSONObject>()
|
|
22
|
-
private var pendingPermission: CallbackContext? = null
|
|
23
|
-
private var pendingLocationPermission: CallbackContext? = null
|
|
24
|
-
|
|
25
|
-
override fun pluginInitialize() {
|
|
26
|
-
core = PushizoBridgeCore(cordova.activity.applicationContext) { type, payload -> sendEvent(type, payload) }
|
|
27
|
-
core.attachIfInitialized()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
override fun execute(action: String, args: JSONArray, callbackContext: CallbackContext): Boolean {
|
|
31
|
-
when (action) {
|
|
32
|
-
"setEventCallback" -> openEventChannel(callbackContext)
|
|
33
|
-
"requestPermission" -> requestPermission(callbackContext)
|
|
34
|
-
"requestLocationPermission" -> requestLocationPermission(args.optJSONObject(0) ?: JSONObject(), callbackContext)
|
|
35
|
-
else -> return core.handle(action, args.optJSONObject(0) ?: JSONObject(), reply(callbackContext))
|
|
36
|
-
}
|
|
37
|
-
return true
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private fun reply(callbackContext: CallbackContext) = object : PushizoBridgeCore.Reply {
|
|
41
|
-
override fun success(data: JSONObject?) {
|
|
42
|
-
if (data == null) callbackContext.success() else callbackContext.success(data)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
override fun error(code: String, message: String?) {
|
|
46
|
-
callbackContext.error(JSONObject().put("code", code).put("message", message ?: code))
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// --- Olay kanalı ---
|
|
51
|
-
|
|
52
|
-
private fun openEventChannel(callbackContext: CallbackContext) {
|
|
53
|
-
val buffered: List<JSONObject>
|
|
54
|
-
synchronized(lock) {
|
|
55
|
-
eventCallback = callbackContext
|
|
56
|
-
buffered = bufferedEvents.toList()
|
|
57
|
-
bufferedEvents.clear()
|
|
58
|
-
}
|
|
59
|
-
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.NO_RESULT).apply { keepCallback = true })
|
|
60
|
-
buffered.forEach { deliver(callbackContext, it) }
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private fun sendEvent(type: String, payload: JSONObject) {
|
|
64
|
-
val message = JSONObject().put("type", type).put("payload", payload)
|
|
65
|
-
val target = synchronized(lock) {
|
|
66
|
-
eventCallback ?: run {
|
|
67
|
-
// JS kanalı henüz açılmadı (soğuk başlatma): sınırlı tampon.
|
|
68
|
-
bufferedEvents.addLast(message)
|
|
69
|
-
while (bufferedEvents.size > MAX_BUFFERED_EVENTS) bufferedEvents.removeFirst()
|
|
70
|
-
null
|
|
71
|
-
}
|
|
72
|
-
} ?: return
|
|
73
|
-
deliver(target, message)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private fun deliver(callbackContext: CallbackContext, message: JSONObject) {
|
|
77
|
-
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, message).apply { keepCallback = true })
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// --- İzin ---
|
|
81
|
-
|
|
82
|
-
/** Android 13+ POST_NOTIFICATIONS istemi; önceki sürümlerde çalışma zamanı izni yoktur, mevcut durum döner. */
|
|
83
|
-
private fun requestPermission(callbackContext: CallbackContext) {
|
|
84
|
-
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || cordova.hasPermission(Manifest.permission.POST_NOTIFICATIONS)) {
|
|
85
|
-
core.onPermissionResult()
|
|
86
|
-
callbackContext.success(core.permissionJson())
|
|
87
|
-
return
|
|
88
|
-
}
|
|
89
|
-
synchronized(lock) { pendingPermission = callbackContext }
|
|
90
|
-
cordova.requestPermission(this, PERMISSION_REQUEST_CODE, Manifest.permission.POST_NOTIFICATIONS)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Konum izni (v2 Faz 17b): açıklama diyaloğu ve manifest denetimi [PushizoBridgeCore] içindedir; "Devam" seçilirse
|
|
95
|
-
* sistem izni `Pushizo.Location.PERMISSION_REQUEST_CODE` ile istenir, sonuç [onRequestPermissionsResult] ile döner.
|
|
96
|
-
*/
|
|
97
|
-
private fun requestLocationPermission(args: JSONObject, callbackContext: CallbackContext) {
|
|
98
|
-
core.requestLocationPermission(cordova.activity, args, reply(callbackContext)) { permissions ->
|
|
99
|
-
// Yanıtsız kalan önceki istek güncel izin durumuyla kapatılır.
|
|
100
|
-
val previous = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = callbackContext } }
|
|
101
|
-
previous?.success(core.locationPermissionJson())
|
|
102
|
-
cordova.requestPermissions(this, Pushizo.Location.PERMISSION_REQUEST_CODE, permissions)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
|
107
|
-
when (requestCode) {
|
|
108
|
-
PERMISSION_REQUEST_CODE -> {
|
|
109
|
-
core.onPermissionResult()
|
|
110
|
-
val callback = synchronized(lock) { pendingPermission.also { pendingPermission = null } } ?: return
|
|
111
|
-
// Sonuç sistem durumundan okunur (izin verilse de bildirimler uygulama ayarından kapalı olabilir).
|
|
112
|
-
callback.success(core.permissionJson())
|
|
113
|
-
}
|
|
114
|
-
Pushizo.Location.PERMISSION_REQUEST_CODE -> {
|
|
115
|
-
// SDK bilgilendirilir (izin verildiyse ve paylaşım açıksa konum gönderilir); sonuç sistem durumundan okunur.
|
|
116
|
-
val result = core.onLocationPermissionResult()
|
|
117
|
-
val callback = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = null } } ?: return
|
|
118
|
-
callback.success(result)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// --- Yaşam döngüsü ---
|
|
124
|
-
|
|
125
|
-
override fun onReset() {
|
|
126
|
-
// Sayfa yeniden yüklendi: eski JS kanalı geçersiz; yeni sayfa `setEventCallback` ile yeniden açar.
|
|
127
|
-
synchronized(lock) { eventCallback = null }
|
|
128
|
-
core.foregroundHandlerEnabled = false
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
override fun onDestroy() {
|
|
132
|
-
core.detach()
|
|
133
|
-
synchronized(lock) { eventCallback = null }
|
|
134
|
-
super.onDestroy()
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
companion object {
|
|
138
|
-
private const val PERMISSION_REQUEST_CODE = 0x4854
|
|
139
|
-
private const val MAX_BUFFERED_EVENTS = 50
|
|
140
|
-
}
|
|
141
|
-
}
|
|
1
|
+
package com.pushizo.cordova
|
|
2
|
+
|
|
3
|
+
import android.Manifest
|
|
4
|
+
import android.os.Build
|
|
5
|
+
import com.pushizo.sdk.Pushizo
|
|
6
|
+
import org.apache.cordova.CallbackContext
|
|
7
|
+
import org.apache.cordova.CordovaPlugin
|
|
8
|
+
import org.apache.cordova.PluginResult
|
|
9
|
+
import org.json.JSONArray
|
|
10
|
+
import org.json.JSONObject
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Cordova → Pushizo Android SDK köprüsü (`cordova.exec` servisi "Pushizo"). Metotlar
|
|
14
|
+
* [PushizoBridgeCore] üzerinden SDK'ya iletilir. SDK olayları JS'in `setEventCallback` ile açtığı tek
|
|
15
|
+
* `keepCallback` kanalından `{ type, payload }` olarak gönderilir; kanal açılmadan gelen olaylar tamponlanır.
|
|
16
|
+
*/
|
|
17
|
+
class PushizoCordovaPlugin : CordovaPlugin() {
|
|
18
|
+
private lateinit var core: PushizoBridgeCore
|
|
19
|
+
private val lock = Any()
|
|
20
|
+
private var eventCallback: CallbackContext? = null
|
|
21
|
+
private val bufferedEvents = ArrayDeque<JSONObject>()
|
|
22
|
+
private var pendingPermission: CallbackContext? = null
|
|
23
|
+
private var pendingLocationPermission: CallbackContext? = null
|
|
24
|
+
|
|
25
|
+
override fun pluginInitialize() {
|
|
26
|
+
core = PushizoBridgeCore(cordova.activity.applicationContext) { type, payload -> sendEvent(type, payload) }
|
|
27
|
+
core.attachIfInitialized()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun execute(action: String, args: JSONArray, callbackContext: CallbackContext): Boolean {
|
|
31
|
+
when (action) {
|
|
32
|
+
"setEventCallback" -> openEventChannel(callbackContext)
|
|
33
|
+
"requestPermission" -> requestPermission(callbackContext)
|
|
34
|
+
"requestLocationPermission" -> requestLocationPermission(args.optJSONObject(0) ?: JSONObject(), callbackContext)
|
|
35
|
+
else -> return core.handle(action, args.optJSONObject(0) ?: JSONObject(), reply(callbackContext))
|
|
36
|
+
}
|
|
37
|
+
return true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private fun reply(callbackContext: CallbackContext) = object : PushizoBridgeCore.Reply {
|
|
41
|
+
override fun success(data: JSONObject?) {
|
|
42
|
+
if (data == null) callbackContext.success() else callbackContext.success(data)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override fun error(code: String, message: String?) {
|
|
46
|
+
callbackContext.error(JSONObject().put("code", code).put("message", message ?: code))
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// --- Olay kanalı ---
|
|
51
|
+
|
|
52
|
+
private fun openEventChannel(callbackContext: CallbackContext) {
|
|
53
|
+
val buffered: List<JSONObject>
|
|
54
|
+
synchronized(lock) {
|
|
55
|
+
eventCallback = callbackContext
|
|
56
|
+
buffered = bufferedEvents.toList()
|
|
57
|
+
bufferedEvents.clear()
|
|
58
|
+
}
|
|
59
|
+
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.NO_RESULT).apply { keepCallback = true })
|
|
60
|
+
buffered.forEach { deliver(callbackContext, it) }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private fun sendEvent(type: String, payload: JSONObject) {
|
|
64
|
+
val message = JSONObject().put("type", type).put("payload", payload)
|
|
65
|
+
val target = synchronized(lock) {
|
|
66
|
+
eventCallback ?: run {
|
|
67
|
+
// JS kanalı henüz açılmadı (soğuk başlatma): sınırlı tampon.
|
|
68
|
+
bufferedEvents.addLast(message)
|
|
69
|
+
while (bufferedEvents.size > MAX_BUFFERED_EVENTS) bufferedEvents.removeFirst()
|
|
70
|
+
null
|
|
71
|
+
}
|
|
72
|
+
} ?: return
|
|
73
|
+
deliver(target, message)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
private fun deliver(callbackContext: CallbackContext, message: JSONObject) {
|
|
77
|
+
callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, message).apply { keepCallback = true })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// --- İzin ---
|
|
81
|
+
|
|
82
|
+
/** Android 13+ POST_NOTIFICATIONS istemi; önceki sürümlerde çalışma zamanı izni yoktur, mevcut durum döner. */
|
|
83
|
+
private fun requestPermission(callbackContext: CallbackContext) {
|
|
84
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || cordova.hasPermission(Manifest.permission.POST_NOTIFICATIONS)) {
|
|
85
|
+
core.onPermissionResult()
|
|
86
|
+
callbackContext.success(core.permissionJson())
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
synchronized(lock) { pendingPermission = callbackContext }
|
|
90
|
+
cordova.requestPermission(this, PERMISSION_REQUEST_CODE, Manifest.permission.POST_NOTIFICATIONS)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Konum izni (v2 Faz 17b): açıklama diyaloğu ve manifest denetimi [PushizoBridgeCore] içindedir; "Devam" seçilirse
|
|
95
|
+
* sistem izni `Pushizo.Location.PERMISSION_REQUEST_CODE` ile istenir, sonuç [onRequestPermissionsResult] ile döner.
|
|
96
|
+
*/
|
|
97
|
+
private fun requestLocationPermission(args: JSONObject, callbackContext: CallbackContext) {
|
|
98
|
+
core.requestLocationPermission(cordova.activity, args, reply(callbackContext)) { permissions ->
|
|
99
|
+
// Yanıtsız kalan önceki istek güncel izin durumuyla kapatılır.
|
|
100
|
+
val previous = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = callbackContext } }
|
|
101
|
+
previous?.success(core.locationPermissionJson())
|
|
102
|
+
cordova.requestPermissions(this, Pushizo.Location.PERMISSION_REQUEST_CODE, permissions)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
|
107
|
+
when (requestCode) {
|
|
108
|
+
PERMISSION_REQUEST_CODE -> {
|
|
109
|
+
core.onPermissionResult()
|
|
110
|
+
val callback = synchronized(lock) { pendingPermission.also { pendingPermission = null } } ?: return
|
|
111
|
+
// Sonuç sistem durumundan okunur (izin verilse de bildirimler uygulama ayarından kapalı olabilir).
|
|
112
|
+
callback.success(core.permissionJson())
|
|
113
|
+
}
|
|
114
|
+
Pushizo.Location.PERMISSION_REQUEST_CODE -> {
|
|
115
|
+
// SDK bilgilendirilir (izin verildiyse ve paylaşım açıksa konum gönderilir); sonuç sistem durumundan okunur.
|
|
116
|
+
val result = core.onLocationPermissionResult()
|
|
117
|
+
val callback = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = null } } ?: return
|
|
118
|
+
callback.success(result)
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// --- Yaşam döngüsü ---
|
|
124
|
+
|
|
125
|
+
override fun onReset() {
|
|
126
|
+
// Sayfa yeniden yüklendi: eski JS kanalı geçersiz; yeni sayfa `setEventCallback` ile yeniden açar.
|
|
127
|
+
synchronized(lock) { eventCallback = null }
|
|
128
|
+
core.foregroundHandlerEnabled = false
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
override fun onDestroy() {
|
|
132
|
+
core.detach()
|
|
133
|
+
synchronized(lock) { eventCallback = null }
|
|
134
|
+
super.onDestroy()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
companion object {
|
|
138
|
+
private const val PERMISSION_REQUEST_CODE = 0x4854
|
|
139
|
+
private const val MAX_BUFFERED_EVENTS = 50
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
package com.pushizo.cordova
|
|
2
|
-
|
|
3
|
-
import android.content.ContentProvider
|
|
4
|
-
import android.content.ContentValues
|
|
5
|
-
import android.database.Cursor
|
|
6
|
-
import android.net.Uri
|
|
7
|
-
import android.os.Handler
|
|
8
|
-
import android.os.Looper
|
|
9
|
-
import com.pushizo.sdk.Pushizo
|
|
10
|
-
import com.pushizo.sdk.HsLog
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Süreç başında (Application.onCreate'ten sonra, ilk Activity/servis çalışmadan önce) kayıtlı ayarlarla SDK'yı
|
|
14
|
-
* başlatır. İlk kurulumda kayıt olmadığından hiçbir şey yapmaz; başlatma JS `initialize` ile olur.
|
|
15
|
-
* Firebase ve androidx.startup sağlayıcılarının tamamlanması için başlatma ana iş parçacığına ertelenir.
|
|
16
|
-
*/
|
|
17
|
-
class PushizoInitProvider : ContentProvider() {
|
|
18
|
-
override fun onCreate(): Boolean {
|
|
19
|
-
val ctx = context?.applicationContext ?: return false
|
|
20
|
-
Handler(Looper.getMainLooper()).post {
|
|
21
|
-
if (Pushizo.isInitialized) return@post
|
|
22
|
-
val config = PushizoConfigStore.load(ctx) ?: return@post
|
|
23
|
-
runCatching { Pushizo.initialize(ctx, config.appId, config.toOptions()) }
|
|
24
|
-
.onFailure { HsLog.w("kayıtlı ayarlarla başlatılamadı", it) }
|
|
25
|
-
}
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
|
30
|
-
override fun getType(uri: Uri): String? = null
|
|
31
|
-
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
|
32
|
-
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
33
|
-
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
34
|
-
}
|
|
1
|
+
package com.pushizo.cordova
|
|
2
|
+
|
|
3
|
+
import android.content.ContentProvider
|
|
4
|
+
import android.content.ContentValues
|
|
5
|
+
import android.database.Cursor
|
|
6
|
+
import android.net.Uri
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
9
|
+
import com.pushizo.sdk.Pushizo
|
|
10
|
+
import com.pushizo.sdk.HsLog
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Süreç başında (Application.onCreate'ten sonra, ilk Activity/servis çalışmadan önce) kayıtlı ayarlarla SDK'yı
|
|
14
|
+
* başlatır. İlk kurulumda kayıt olmadığından hiçbir şey yapmaz; başlatma JS `initialize` ile olur.
|
|
15
|
+
* Firebase ve androidx.startup sağlayıcılarının tamamlanması için başlatma ana iş parçacığına ertelenir.
|
|
16
|
+
*/
|
|
17
|
+
class PushizoInitProvider : ContentProvider() {
|
|
18
|
+
override fun onCreate(): Boolean {
|
|
19
|
+
val ctx = context?.applicationContext ?: return false
|
|
20
|
+
Handler(Looper.getMainLooper()).post {
|
|
21
|
+
if (Pushizo.isInitialized) return@post
|
|
22
|
+
val config = PushizoConfigStore.load(ctx) ?: return@post
|
|
23
|
+
runCatching { Pushizo.initialize(ctx, config.appId, config.toOptions()) }
|
|
24
|
+
.onFailure { HsLog.w("kayıtlı ayarlarla başlatılamadı", it) }
|
|
25
|
+
}
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override fun query(uri: Uri, projection: Array<out String>?, selection: String?, selectionArgs: Array<out String>?, sortOrder: String?): Cursor? = null
|
|
30
|
+
override fun getType(uri: Uri): String? = null
|
|
31
|
+
override fun insert(uri: Uri, values: ContentValues?): Uri? = null
|
|
32
|
+
override fun delete(uri: Uri, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
33
|
+
override fun update(uri: Uri, values: ContentValues?, selection: String?, selectionArgs: Array<out String>?): Int = 0
|
|
34
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
// Pushizo Android SDK deposu: Maven Central yayını öncesinde `sdk/android` içinde
|
|
2
|
-
// `gradle :pushizo:publishToMavenLocal` ile yerel Maven deposuna kurulan artefakt kullanılabilir.
|
|
3
|
-
repositories {
|
|
4
|
-
mavenCentral()
|
|
5
|
-
mavenLocal()
|
|
6
|
-
}
|
|
1
|
+
// Pushizo Android SDK deposu: Maven Central yayını öncesinde `sdk/android` içinde
|
|
2
|
+
// `gradle :pushizo:publishToMavenLocal` ile yerel Maven deposuna kurulan artefakt kullanılabilir.
|
|
3
|
+
repositories {
|
|
4
|
+
mavenCentral()
|
|
5
|
+
mavenLocal()
|
|
6
|
+
}
|
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
import Pushizo
|
|
3
|
-
#if canImport(PushizoCore)
|
|
4
|
-
import PushizoCore
|
|
5
|
-
#endif
|
|
6
|
-
import ObjectiveC
|
|
7
|
-
import UIKit
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
Cordova uygulamalarında AppDelegate eklenti tarafından değiştirilemediğinden APNs token geri çağrıları çalışma
|
|
11
|
-
zamanında AppDelegate sınıfına eklenir. Uygulama bu metotları zaten uyguluyorsa önce SDK'ya iletilir, ardından
|
|
12
|
-
özgün uygulama çağrılır; uygulamıyorsa yalnızca SDK'ya iletilir. Bir kez kurulur.
|
|
13
|
-
*/
|
|
14
|
-
enum PushizoAppDelegateHook {
|
|
15
|
-
private static var installed = false
|
|
16
|
-
|
|
17
|
-
private typealias TokenImp = @convention(c) (AnyObject, Selector, UIApplication, NSData) -> Void
|
|
18
|
-
private typealias ErrorImp = @convention(c) (AnyObject, Selector, UIApplication, NSError) -> Void
|
|
19
|
-
|
|
20
|
-
static func install() {
|
|
21
|
-
guard !installed, let delegate = UIApplication.shared.delegate else { return }
|
|
22
|
-
installed = true
|
|
23
|
-
let cls: AnyClass = type(of: delegate)
|
|
24
|
-
|
|
25
|
-
let tokenSelector = #selector(UIApplicationDelegate.application(_:didRegisterForRemoteNotificationsWithDeviceToken:))
|
|
26
|
-
let originalToken = class_getInstanceMethod(cls, tokenSelector).map { unsafeBitCast(method_getImplementation($0), to: TokenImp.self) }
|
|
27
|
-
let tokenBlock: @convention(block) (AnyObject, UIApplication, NSData) -> Void = { receiver, application, token in
|
|
28
|
-
Pushizo.setDeviceToken(token as Data)
|
|
29
|
-
originalToken?(receiver, tokenSelector, application, token)
|
|
30
|
-
}
|
|
31
|
-
replace(cls, tokenSelector, imp_implementationWithBlock(tokenBlock))
|
|
32
|
-
|
|
33
|
-
let errorSelector = #selector(UIApplicationDelegate.application(_:didFailToRegisterForRemoteNotificationsWithError:))
|
|
34
|
-
let originalError = class_getInstanceMethod(cls, errorSelector).map { unsafeBitCast(method_getImplementation($0), to: ErrorImp.self) }
|
|
35
|
-
let errorBlock: @convention(block) (AnyObject, UIApplication, NSError) -> Void = { receiver, application, error in
|
|
36
|
-
Pushizo.setDeviceTokenError(error)
|
|
37
|
-
originalError?(receiver, errorSelector, application, error)
|
|
38
|
-
}
|
|
39
|
-
replace(cls, errorSelector, imp_implementationWithBlock(errorBlock))
|
|
40
|
-
|
|
41
|
-
// UIKit delegenin yanıtladığı seçicileri atama anında önbelleğe alır; yeni metotların görülmesi için yeniden atanır.
|
|
42
|
-
let application = UIApplication.shared
|
|
43
|
-
application.delegate = nil
|
|
44
|
-
application.delegate = delegate
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/// Sınıfın kendisinde metot yoksa eklenir (üst sınıf uygulaması `original` ile çağrılır), varsa değiştirilir.
|
|
48
|
-
private static func replace(_ cls: AnyClass, _ selector: Selector, _ imp: IMP) {
|
|
49
|
-
let types = "v@:@@"
|
|
50
|
-
if !class_addMethod(cls, selector, imp, types), let method = class_getInstanceMethod(cls, selector) {
|
|
51
|
-
method_setImplementation(method, imp)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
1
|
+
import Foundation
|
|
2
|
+
import Pushizo
|
|
3
|
+
#if canImport(PushizoCore)
|
|
4
|
+
import PushizoCore
|
|
5
|
+
#endif
|
|
6
|
+
import ObjectiveC
|
|
7
|
+
import UIKit
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
Cordova uygulamalarında AppDelegate eklenti tarafından değiştirilemediğinden APNs token geri çağrıları çalışma
|
|
11
|
+
zamanında AppDelegate sınıfına eklenir. Uygulama bu metotları zaten uyguluyorsa önce SDK'ya iletilir, ardından
|
|
12
|
+
özgün uygulama çağrılır; uygulamıyorsa yalnızca SDK'ya iletilir. Bir kez kurulur.
|
|
13
|
+
*/
|
|
14
|
+
enum PushizoAppDelegateHook {
|
|
15
|
+
private static var installed = false
|
|
16
|
+
|
|
17
|
+
private typealias TokenImp = @convention(c) (AnyObject, Selector, UIApplication, NSData) -> Void
|
|
18
|
+
private typealias ErrorImp = @convention(c) (AnyObject, Selector, UIApplication, NSError) -> Void
|
|
19
|
+
|
|
20
|
+
static func install() {
|
|
21
|
+
guard !installed, let delegate = UIApplication.shared.delegate else { return }
|
|
22
|
+
installed = true
|
|
23
|
+
let cls: AnyClass = type(of: delegate)
|
|
24
|
+
|
|
25
|
+
let tokenSelector = #selector(UIApplicationDelegate.application(_:didRegisterForRemoteNotificationsWithDeviceToken:))
|
|
26
|
+
let originalToken = class_getInstanceMethod(cls, tokenSelector).map { unsafeBitCast(method_getImplementation($0), to: TokenImp.self) }
|
|
27
|
+
let tokenBlock: @convention(block) (AnyObject, UIApplication, NSData) -> Void = { receiver, application, token in
|
|
28
|
+
Pushizo.setDeviceToken(token as Data)
|
|
29
|
+
originalToken?(receiver, tokenSelector, application, token)
|
|
30
|
+
}
|
|
31
|
+
replace(cls, tokenSelector, imp_implementationWithBlock(tokenBlock))
|
|
32
|
+
|
|
33
|
+
let errorSelector = #selector(UIApplicationDelegate.application(_:didFailToRegisterForRemoteNotificationsWithError:))
|
|
34
|
+
let originalError = class_getInstanceMethod(cls, errorSelector).map { unsafeBitCast(method_getImplementation($0), to: ErrorImp.self) }
|
|
35
|
+
let errorBlock: @convention(block) (AnyObject, UIApplication, NSError) -> Void = { receiver, application, error in
|
|
36
|
+
Pushizo.setDeviceTokenError(error)
|
|
37
|
+
originalError?(receiver, errorSelector, application, error)
|
|
38
|
+
}
|
|
39
|
+
replace(cls, errorSelector, imp_implementationWithBlock(errorBlock))
|
|
40
|
+
|
|
41
|
+
// UIKit delegenin yanıtladığı seçicileri atama anında önbelleğe alır; yeni metotların görülmesi için yeniden atanır.
|
|
42
|
+
let application = UIApplication.shared
|
|
43
|
+
application.delegate = nil
|
|
44
|
+
application.delegate = delegate
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Sınıfın kendisinde metot yoksa eklenir (üst sınıf uygulaması `original` ile çağrılır), varsa değiştirilir.
|
|
48
|
+
private static func replace(_ cls: AnyClass, _ selector: Selector, _ imp: IMP) {
|
|
49
|
+
let types = "v@:@@"
|
|
50
|
+
if !class_addMethod(cls, selector, imp, types), let method = class_getInstanceMethod(cls, selector) {
|
|
51
|
+
method_setImplementation(method, imp)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|