cordova-plugin-pushizo 0.1.0 → 0.3.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.
@@ -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,163 @@
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
+ private var pendingBackgroundLocationPermission: CallbackContext? = null
25
+
26
+ override fun pluginInitialize() {
27
+ core = PushizoBridgeCore(cordova.activity.applicationContext) { type, payload -> sendEvent(type, payload) }
28
+ core.activityProvider = { cordova.activity }
29
+ core.attachIfInitialized()
30
+ }
31
+
32
+ override fun execute(action: String, args: JSONArray, callbackContext: CallbackContext): Boolean {
33
+ when (action) {
34
+ "setEventCallback" -> openEventChannel(callbackContext)
35
+ "requestPermission" -> requestPermission(callbackContext)
36
+ "requestLocationPermission" -> requestLocationPermission(args.optJSONObject(0) ?: JSONObject(), callbackContext)
37
+ "requestBackgroundLocationPermission" -> requestBackgroundLocationPermission(args.optJSONObject(0) ?: JSONObject(), callbackContext)
38
+ else -> return core.handle(action, args.optJSONObject(0) ?: JSONObject(), reply(callbackContext))
39
+ }
40
+ return true
41
+ }
42
+
43
+ private fun reply(callbackContext: CallbackContext) = object : PushizoBridgeCore.Reply {
44
+ override fun success(data: JSONObject?) {
45
+ if (data == null) callbackContext.success() else callbackContext.success(data)
46
+ }
47
+
48
+ override fun error(code: String, message: String?) {
49
+ callbackContext.error(JSONObject().put("code", code).put("message", message ?: code))
50
+ }
51
+ }
52
+
53
+ // --- Olay kanalı ---
54
+
55
+ private fun openEventChannel(callbackContext: CallbackContext) {
56
+ val buffered: List<JSONObject>
57
+ synchronized(lock) {
58
+ eventCallback = callbackContext
59
+ buffered = bufferedEvents.toList()
60
+ bufferedEvents.clear()
61
+ }
62
+ callbackContext.sendPluginResult(PluginResult(PluginResult.Status.NO_RESULT).apply { keepCallback = true })
63
+ buffered.forEach { deliver(callbackContext, it) }
64
+ }
65
+
66
+ private fun sendEvent(type: String, payload: JSONObject) {
67
+ val message = JSONObject().put("type", type).put("payload", payload)
68
+ val target = synchronized(lock) {
69
+ eventCallback ?: run {
70
+ // JS kanalı henüz açılmadı (soğuk başlatma): sınırlı tampon.
71
+ bufferedEvents.addLast(message)
72
+ while (bufferedEvents.size > MAX_BUFFERED_EVENTS) bufferedEvents.removeFirst()
73
+ null
74
+ }
75
+ } ?: return
76
+ deliver(target, message)
77
+ }
78
+
79
+ private fun deliver(callbackContext: CallbackContext, message: JSONObject) {
80
+ callbackContext.sendPluginResult(PluginResult(PluginResult.Status.OK, message).apply { keepCallback = true })
81
+ }
82
+
83
+ // --- İzin ---
84
+
85
+ /** Android 13+ POST_NOTIFICATIONS istemi; önceki sürümlerde çalışma zamanı izni yoktur, mevcut durum döner. */
86
+ private fun requestPermission(callbackContext: CallbackContext) {
87
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU || cordova.hasPermission(Manifest.permission.POST_NOTIFICATIONS)) {
88
+ core.onPermissionResult()
89
+ callbackContext.success(core.permissionJson())
90
+ return
91
+ }
92
+ synchronized(lock) { pendingPermission = callbackContext }
93
+ cordova.requestPermission(this, PERMISSION_REQUEST_CODE, Manifest.permission.POST_NOTIFICATIONS)
94
+ }
95
+
96
+ /**
97
+ * Konum izni (v2 Faz 17b): açıklama diyaloğu ve manifest denetimi [PushizoBridgeCore] içindedir; "Devam" seçilirse
98
+ * sistem izni `Pushizo.Location.PERMISSION_REQUEST_CODE` ile istenir, sonuç [onRequestPermissionsResult] ile döner.
99
+ */
100
+ private fun requestLocationPermission(args: JSONObject, callbackContext: CallbackContext) {
101
+ core.requestLocationPermission(cordova.activity, args, reply(callbackContext)) { permissions ->
102
+ // Yanıtsız kalan önceki istek güncel izin durumuyla kapatılır.
103
+ val previous = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = callbackContext } }
104
+ previous?.success(core.locationPermissionJson())
105
+ cordova.requestPermissions(this, Pushizo.Location.PERMISSION_REQUEST_CODE, permissions)
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Arka plan konum izni (ADR-0065): açıklama diyaloğu ve manifest denetimi [PushizoBridgeCore] içindedir; "Devam"
111
+ * seçilirse sistem izni [BACKGROUND_LOCATION_REQUEST_CODE] ile istenir, sonuç [onRequestPermissionsResult] ile döner.
112
+ */
113
+ private fun requestBackgroundLocationPermission(args: JSONObject, callbackContext: CallbackContext) {
114
+ core.requestBackgroundLocationPermission(cordova.activity, args, reply(callbackContext)) { permissions ->
115
+ // Yanıtsız kalan önceki istek güncel izin durumuyla kapatılır.
116
+ val previous = synchronized(lock) { pendingBackgroundLocationPermission.also { pendingBackgroundLocationPermission = callbackContext } }
117
+ previous?.success(core.backgroundLocationPermissionJson())
118
+ cordova.requestPermissions(this, BACKGROUND_LOCATION_REQUEST_CODE, permissions)
119
+ }
120
+ }
121
+
122
+ override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
123
+ when (requestCode) {
124
+ PERMISSION_REQUEST_CODE -> {
125
+ core.onPermissionResult()
126
+ val callback = synchronized(lock) { pendingPermission.also { pendingPermission = null } } ?: return
127
+ // Sonuç sistem durumundan okunur (izin verilse de bildirimler uygulama ayarından kapalı olabilir).
128
+ callback.success(core.permissionJson())
129
+ }
130
+ Pushizo.Location.PERMISSION_REQUEST_CODE -> {
131
+ // SDK bilgilendirilir (izin verildiyse ve paylaşım açıksa konum gönderilir); sonuç sistem durumundan okunur.
132
+ val result = core.onLocationPermissionResult()
133
+ val callback = synchronized(lock) { pendingLocationPermission.also { pendingLocationPermission = null } } ?: return
134
+ callback.success(result)
135
+ }
136
+ BACKGROUND_LOCATION_REQUEST_CODE -> {
137
+ val result = core.onBackgroundLocationPermissionResult()
138
+ val callback = synchronized(lock) { pendingBackgroundLocationPermission.also { pendingBackgroundLocationPermission = null } } ?: return
139
+ callback.success(result)
140
+ }
141
+ }
142
+ }
143
+
144
+ // --- Yaşam döngüsü ---
145
+
146
+ override fun onReset() {
147
+ // Sayfa yeniden yüklendi: eski JS kanalı geçersiz; yeni sayfa `setEventCallback` ile yeniden açar.
148
+ synchronized(lock) { eventCallback = null }
149
+ core.foregroundHandlerEnabled = false
150
+ }
151
+
152
+ override fun onDestroy() {
153
+ core.detach()
154
+ synchronized(lock) { eventCallback = null }
155
+ super.onDestroy()
156
+ }
157
+
158
+ companion object {
159
+ private const val PERMISSION_REQUEST_CODE = 0x4854
160
+ private const val BACKGROUND_LOCATION_REQUEST_CODE = 0x4855
161
+ private const val MAX_BUFFERED_EVENTS = 50
162
+ }
163
+ }
@@ -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
+ }