native-update-capacitor 0.0.0-stage → 4.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.
Files changed (139) hide show
  1. package/AI-INTEGRATION-GUIDE.md +578 -0
  2. package/LICENSE +25 -0
  3. package/NativeUpdate.podspec +19 -0
  4. package/README.md +574 -2
  5. package/android/build.gradle +125 -0
  6. package/android/consumer-rules.pro +9 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +8 -0
  8. package/android/gradle.properties +17 -0
  9. package/android/manifest-additions.xml +28 -0
  10. package/android/proguard-rules.pro +26 -0
  11. package/android/settings.gradle +2 -0
  12. package/android/src/main/AndroidManifest.xml +13 -0
  13. package/android/src/main/java/com/aoneahsan/nativeupdate/AppReviewPlugin.kt +159 -0
  14. package/android/src/main/java/com/aoneahsan/nativeupdate/AppUpdatePlugin.kt +314 -0
  15. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundNotificationManager.kt +406 -0
  16. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateManager.kt +48 -0
  17. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdatePlugin.kt +343 -0
  18. package/android/src/main/java/com/aoneahsan/nativeupdate/BackgroundUpdateWorker.kt +236 -0
  19. package/android/src/main/java/com/aoneahsan/nativeupdate/JsonOptional.kt +26 -0
  20. package/android/src/main/java/com/aoneahsan/nativeupdate/LiveUpdatePlugin.kt +1249 -0
  21. package/android/src/main/java/com/aoneahsan/nativeupdate/NativeUpdatePlugin.kt +404 -0
  22. package/android/src/main/java/com/aoneahsan/nativeupdate/NotificationActionReceiver.kt +107 -0
  23. package/android/src/main/java/com/aoneahsan/nativeupdate/SecurityManager.kt +240 -0
  24. package/android/variables.gradle +5 -0
  25. package/cli/commands/backend-create.js +623 -0
  26. package/cli/commands/bundle-create.js +145 -0
  27. package/cli/commands/bundle-sign.js +64 -0
  28. package/cli/commands/bundle-verify.js +58 -0
  29. package/cli/commands/init.js +146 -0
  30. package/cli/commands/keys-generate.js +58 -0
  31. package/cli/commands/monitor.js +89 -0
  32. package/cli/commands/remote-shared.js +262 -0
  33. package/cli/commands/remote.js +622 -0
  34. package/cli/commands/server-start.js +96 -0
  35. package/cli/index.js +605 -0
  36. package/cli/package.json +21 -0
  37. package/dist/esm/app-review/app-review-manager.d.ts +24 -0
  38. package/dist/esm/app-review/app-review-manager.js +194 -0
  39. package/dist/esm/app-review/index.d.ts +5 -0
  40. package/dist/esm/app-review/index.js +5 -0
  41. package/dist/esm/app-review/platform-review-handler.d.ts +20 -0
  42. package/dist/esm/app-review/platform-review-handler.js +137 -0
  43. package/dist/esm/app-review/review-conditions-checker.d.ts +22 -0
  44. package/dist/esm/app-review/review-conditions-checker.js +154 -0
  45. package/dist/esm/app-review/review-rate-limiter.d.ts +23 -0
  46. package/dist/esm/app-review/review-rate-limiter.js +163 -0
  47. package/dist/esm/app-review/types.d.ts +41 -0
  48. package/dist/esm/app-review/types.js +1 -0
  49. package/dist/esm/app-update/app-update-checker.d.ts +58 -0
  50. package/dist/esm/app-update/app-update-checker.js +227 -0
  51. package/dist/esm/app-update/app-update-installer.d.ts +20 -0
  52. package/dist/esm/app-update/app-update-installer.js +134 -0
  53. package/dist/esm/app-update/app-update-manager.d.ts +28 -0
  54. package/dist/esm/app-update/app-update-manager.js +198 -0
  55. package/dist/esm/app-update/app-update-notifier.d.ts +14 -0
  56. package/dist/esm/app-update/app-update-notifier.js +99 -0
  57. package/dist/esm/app-update/index.d.ts +6 -0
  58. package/dist/esm/app-update/index.js +6 -0
  59. package/dist/esm/app-update/platform-app-update.d.ts +19 -0
  60. package/dist/esm/app-update/platform-app-update.js +138 -0
  61. package/dist/esm/app-update/types.d.ts +58 -0
  62. package/dist/esm/app-update/types.js +11 -0
  63. package/dist/esm/background-update/background-scheduler.d.ts +63 -0
  64. package/dist/esm/background-update/background-scheduler.js +332 -0
  65. package/dist/esm/background-update/index.d.ts +3 -0
  66. package/dist/esm/background-update/index.js +2 -0
  67. package/dist/esm/background-update/notification-manager.d.ts +29 -0
  68. package/dist/esm/background-update/notification-manager.js +88 -0
  69. package/dist/esm/config/support.d.ts +9 -0
  70. package/dist/esm/config/support.js +9 -0
  71. package/dist/esm/core/analytics.d.ts +83 -0
  72. package/dist/esm/core/analytics.js +151 -0
  73. package/dist/esm/core/cache-manager.d.ts +72 -0
  74. package/dist/esm/core/cache-manager.js +274 -0
  75. package/dist/esm/core/config.d.ts +69 -0
  76. package/dist/esm/core/config.js +107 -0
  77. package/dist/esm/core/errors.d.ts +56 -0
  78. package/dist/esm/core/errors.js +85 -0
  79. package/dist/esm/core/event-emitter.d.ts +30 -0
  80. package/dist/esm/core/event-emitter.js +80 -0
  81. package/dist/esm/core/logger.d.ts +21 -0
  82. package/dist/esm/core/logger.js +108 -0
  83. package/dist/esm/core/performance.d.ts +53 -0
  84. package/dist/esm/core/performance.js +153 -0
  85. package/dist/esm/core/plugin-manager.d.ts +88 -0
  86. package/dist/esm/core/plugin-manager.js +224 -0
  87. package/dist/esm/core/security.d.ts +123 -0
  88. package/dist/esm/core/security.js +361 -0
  89. package/dist/esm/core/update-check.d.ts +121 -0
  90. package/dist/esm/core/update-check.js +127 -0
  91. package/dist/esm/definitions.d.ts +872 -0
  92. package/dist/esm/definitions.js +104 -0
  93. package/dist/esm/index.d.ts +14 -0
  94. package/dist/esm/index.js +18 -0
  95. package/dist/esm/live-update/bundle-manager.d.ts +102 -0
  96. package/dist/esm/live-update/bundle-manager.js +344 -0
  97. package/dist/esm/live-update/certificate-pinning.d.ts +38 -0
  98. package/dist/esm/live-update/certificate-pinning.js +77 -0
  99. package/dist/esm/live-update/delta-processor.d.ts +84 -0
  100. package/dist/esm/live-update/delta-processor.js +257 -0
  101. package/dist/esm/live-update/download-manager.d.ts +106 -0
  102. package/dist/esm/live-update/download-manager.js +412 -0
  103. package/dist/esm/live-update/rollout-checker.d.ts +86 -0
  104. package/dist/esm/live-update/rollout-checker.js +304 -0
  105. package/dist/esm/live-update/update-manager.d.ts +63 -0
  106. package/dist/esm/live-update/update-manager.js +321 -0
  107. package/dist/esm/live-update/version-manager.d.ts +93 -0
  108. package/dist/esm/live-update/version-manager.js +390 -0
  109. package/dist/esm/plugin.d.ts +3 -0
  110. package/dist/esm/plugin.js +848 -0
  111. package/dist/esm/security/crypto.d.ts +88 -0
  112. package/dist/esm/security/crypto.js +228 -0
  113. package/dist/esm/security/validator.d.ts +60 -0
  114. package/dist/esm/security/validator.js +142 -0
  115. package/dist/esm/types/app-identity.d.ts +36 -0
  116. package/dist/esm/types/app-identity.js +1 -0
  117. package/dist/esm/types/rollout.d.ts +91 -0
  118. package/dist/esm/types/rollout.js +25 -0
  119. package/dist/esm/web.d.ts +130 -0
  120. package/dist/esm/web.js +981 -0
  121. package/dist/plugin.cjs +1 -0
  122. package/dist/plugin.esm.js +1 -0
  123. package/dist/plugin.js +2 -0
  124. package/docs/CHANGELOG.md +993 -0
  125. package/docs/KNOWN_LIMITATIONS.md +235 -0
  126. package/docs/MIGRATION.md +391 -0
  127. package/docs/protocol/CLIENT-PROTOCOL.md +178 -0
  128. package/docs/server-requirements.md +211 -0
  129. package/ios/Plugin/AppReview/AppReviewPlugin.swift +158 -0
  130. package/ios/Plugin/AppUpdate/AppUpdatePlugin.swift +249 -0
  131. package/ios/Plugin/BackgroundUpdate/BackgroundNotificationManager.swift +333 -0
  132. package/ios/Plugin/BackgroundUpdate/BackgroundUpdatePlugin.swift +464 -0
  133. package/ios/Plugin/Info.plist +43 -0
  134. package/ios/Plugin/LiveUpdate/LiveUpdatePlugin.swift +1286 -0
  135. package/ios/Plugin/LiveUpdate/WebViewConfiguration.swift +45 -0
  136. package/ios/Plugin/NativeUpdatePlugin.m +53 -0
  137. package/ios/Plugin/NativeUpdatePlugin.swift +315 -0
  138. package/ios/Plugin/Security/SecurityManager.swift +289 -0
  139. package/package.json +135 -4
@@ -0,0 +1,464 @@
1
+ import Foundation
2
+ import Capacitor
3
+ import BackgroundTasks
4
+ import UserNotifications
5
+
6
+ /// BackgroundUpdatePlugin schedules silent OTA update checks via
7
+ /// `BGAppRefreshTask` on iOS 13+. The host app **must** declare the
8
+ /// scheduler identifier in its own `Info.plist` — the framework's plist
9
+ /// declaration does not propagate into the app bundle. Add:
10
+ ///
11
+ /// <key>BGTaskSchedulerPermittedIdentifiers</key>
12
+ /// <array>
13
+ /// <string>com.aoneahsan.nativeupdate.background</string>
14
+ /// </array>
15
+ ///
16
+ /// and (for the Capabilities pane) ensure `background-app-refresh` is
17
+ /// listed under `UIBackgroundModes`. Without those entries iOS will
18
+ /// silently refuse to register the task and background updates never
19
+ /// run — there is no runtime error.
20
+ @objc(BackgroundUpdatePlugin)
21
+ public class BackgroundUpdatePlugin: CAPPlugin {
22
+
23
+ private let backgroundTaskIdentifier = "com.aoneahsan.nativeupdate.background"
24
+ private var backgroundUpdateConfig: BackgroundUpdateConfig?
25
+ private var backgroundUpdateStatus = BackgroundUpdateStatus(
26
+ enabled: false,
27
+ isRunning: false,
28
+ checkCount: 0,
29
+ failureCount: 0
30
+ )
31
+ private var notificationManager: BackgroundNotificationManager?
32
+ private var appUpdateProvider: (() async -> AppUpdateInfo?)?
33
+ private var liveUpdateProvider: (() async -> LatestVersion?)?
34
+ private var eventListener: ((String, [String: Any]) -> Void)?
35
+
36
+ func configureProviders(
37
+ appUpdate: @escaping () async -> AppUpdateInfo?,
38
+ liveUpdate: @escaping () async -> LatestVersion?,
39
+ eventListener: @escaping (String, [String: Any]) -> Void
40
+ ) {
41
+ appUpdateProvider = appUpdate
42
+ liveUpdateProvider = liveUpdate
43
+ self.eventListener = eventListener
44
+ }
45
+
46
+ public override func load() {
47
+ super.load()
48
+
49
+ // Initialize notification manager
50
+ notificationManager = BackgroundNotificationManager(plugin: self)
51
+
52
+ // Register background task
53
+ if #available(iOS 13.0, *) {
54
+ BGTaskScheduler.shared.register(forTaskWithIdentifier: backgroundTaskIdentifier, using: nil) { task in
55
+ guard let refreshTask = task as? BGAppRefreshTask else {
56
+ // Force-casting here would crash the host app process
57
+ // if Apple ever delivers a different concrete type.
58
+ task.setTaskCompleted(success: false)
59
+ return
60
+ }
61
+ self.handleBackgroundTask(task: refreshTask)
62
+ }
63
+ }
64
+ }
65
+
66
+ func configure(_ config: [String: Any]) throws {
67
+ // Configuration is handled in enableBackgroundUpdates
68
+ // This method exists for consistency with other plugins
69
+ }
70
+
71
+ @objc func enableBackgroundUpdates(_ call: CAPPluginCall) {
72
+ guard let configData = call.options else {
73
+ call.reject("Missing configuration")
74
+ return
75
+ }
76
+
77
+ do {
78
+ // Convert [AnyHashable: Any] to [String: Any]
79
+ let stringKeyedConfig = configData.reduce(into: [String: Any]()) { result, pair in
80
+ if let key = pair.key as? String {
81
+ result[key] = pair.value
82
+ }
83
+ }
84
+ let config = try BackgroundUpdateConfig.from(stringKeyedConfig)
85
+ backgroundUpdateConfig = config
86
+ backgroundUpdateStatus.enabled = config.enabled
87
+
88
+ if config.enabled {
89
+ scheduleBackgroundTask(interval: config.checkInterval)
90
+ } else {
91
+ disableBackgroundUpdates()
92
+ }
93
+
94
+ call.resolve()
95
+ } catch {
96
+ call.reject("Invalid configuration: \(error.localizedDescription)")
97
+ }
98
+ }
99
+
100
+ @objc func disableBackgroundUpdates(_ call: CAPPluginCall) {
101
+ disableBackgroundUpdates()
102
+ call.resolve()
103
+ }
104
+
105
+ @objc func getBackgroundUpdateStatus(_ call: CAPPluginCall) {
106
+ call.resolve(backgroundUpdateStatus.toDictionary())
107
+ }
108
+
109
+ @objc func scheduleBackgroundCheck(_ call: CAPPluginCall) {
110
+ guard let interval = call.getDouble("interval") else {
111
+ call.reject("Missing interval parameter")
112
+ return
113
+ }
114
+
115
+ scheduleBackgroundTask(interval: Int(interval))
116
+ call.resolve()
117
+ }
118
+
119
+ @objc func triggerBackgroundCheck(_ call: CAPPluginCall) {
120
+ Task {
121
+ let result = await performBackgroundCheck()
122
+ call.resolve(result.toDictionary())
123
+ }
124
+ }
125
+
126
+ @objc func setNotificationPreferences(_ call: CAPPluginCall) {
127
+ guard let preferences = call.options else {
128
+ call.reject("Missing preferences")
129
+ return
130
+ }
131
+
132
+ // Convert [AnyHashable: Any] to [String: Any]
133
+ let stringKeyedPreferences = preferences.reduce(into: [String: Any]()) { result, pair in
134
+ if let key = pair.key as? String {
135
+ result[key] = pair.value
136
+ }
137
+ }
138
+
139
+ notificationManager?.setPreferences(stringKeyedPreferences)
140
+ call.resolve()
141
+ }
142
+
143
+ @objc func getNotificationPermissions(_ call: CAPPluginCall) {
144
+ notificationManager?.getPermissionStatus { status in
145
+ call.resolve(status.toDictionary())
146
+ }
147
+ }
148
+
149
+ @objc func requestNotificationPermissions(_ call: CAPPluginCall) {
150
+ notificationManager?.requestPermissions { granted in
151
+ call.resolve(["granted": granted])
152
+ }
153
+ }
154
+
155
+ // MARK: - Private Methods
156
+
157
+ /// Plain Swift call — used by `NativeUpdatePlugin.cleanup()` so it
158
+ /// doesn't have to manufacture a `CAPPluginCall` (the relevant
159
+ /// initializer is internal in the public Capacitor SDK).
160
+ func disableBackgroundUpdatesInternal() {
161
+ backgroundUpdateStatus.enabled = false
162
+ backgroundUpdateStatus.isRunning = false
163
+ backgroundUpdateStatus.currentTaskId = nil
164
+
165
+ if #available(iOS 13.0, *) {
166
+ BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: backgroundTaskIdentifier)
167
+ }
168
+ }
169
+
170
+ private func disableBackgroundUpdates() {
171
+ disableBackgroundUpdatesInternal()
172
+ }
173
+
174
+ private func scheduleBackgroundTask(interval: Int) {
175
+ guard #available(iOS 13.0, *) else {
176
+ NSLog("[native-update] BackgroundTasks framework not available on iOS < 13.0")
177
+ return
178
+ }
179
+
180
+ // Cancel any prior pending request with this identifier before
181
+ // submitting a new one. iOS documents submit() as replacing an
182
+ // existing request of the same identifier, but a few OS versions
183
+ // have been observed to fail the second submit with an
184
+ // already-scheduled error instead of replacing. Explicit cancel
185
+ // is the reliable path.
186
+ BGTaskScheduler.shared.cancel(taskRequestWithIdentifier: backgroundTaskIdentifier)
187
+
188
+ let request = BGAppRefreshTaskRequest(identifier: backgroundTaskIdentifier)
189
+ request.earliestBeginDate = Date(timeIntervalSinceNow: TimeInterval(interval / 1000))
190
+
191
+ do {
192
+ try BGTaskScheduler.shared.submit(request)
193
+ backgroundUpdateStatus.nextCheckTime = Int(Date().timeIntervalSince1970 * 1000) + interval
194
+ NSLog("[native-update] Background task scheduled for \(interval)ms from now")
195
+ } catch let error as BGTaskScheduler.Error {
196
+ // Surface a specific diagnostic. .notPermitted almost always
197
+ // means the host app's Info.plist is missing the scheduler
198
+ // identifier — which is a silent failure mode otherwise.
199
+ switch error.code {
200
+ case .notPermitted:
201
+ NSLog("[native-update] BGTaskScheduler .notPermitted — host app is missing BGTaskSchedulerPermittedIdentifiers entry for \(backgroundTaskIdentifier) in Info.plist")
202
+ case .tooManyPendingTaskRequests:
203
+ NSLog("[native-update] BGTaskScheduler .tooManyPendingTaskRequests — another task is already queued; background updates will run on the existing schedule")
204
+ case .unavailable:
205
+ NSLog("[native-update] BGTaskScheduler .unavailable — background tasks are disabled on this device (likely simulator or Low Power Mode)")
206
+ case .immediateRunIneligible:
207
+ NSLog("[native-update] BGTaskScheduler immediate run is ineligible; the next scheduled refresh will be used")
208
+ @unknown default:
209
+ NSLog("[native-update] Failed to schedule background task: \(error.localizedDescription)")
210
+ }
211
+ backgroundUpdateStatus.lastError = UpdateError(
212
+ code: "BGTASK_SUBMIT_FAILED",
213
+ message: error.localizedDescription
214
+ )
215
+ } catch {
216
+ NSLog("[native-update] Failed to schedule background task: \(error.localizedDescription)")
217
+ backgroundUpdateStatus.lastError = UpdateError(
218
+ code: "BGTASK_SUBMIT_FAILED",
219
+ message: error.localizedDescription
220
+ )
221
+ }
222
+ }
223
+
224
+ @available(iOS 13.0, *)
225
+ private func handleBackgroundTask(task: BGAppRefreshTask) {
226
+ NSLog("Background task started")
227
+
228
+ // Schedule next task
229
+ if let config = backgroundUpdateConfig {
230
+ scheduleBackgroundTask(interval: config.checkInterval)
231
+ }
232
+
233
+ // Set expiration handler
234
+ task.expirationHandler = {
235
+ NSLog("Background task expired")
236
+ self.backgroundUpdateStatus.isRunning = false
237
+ task.setTaskCompleted(success: false)
238
+ }
239
+
240
+ // Perform background check
241
+ Task {
242
+ let result = await performBackgroundCheck()
243
+
244
+ // Notify listeners
245
+ await MainActor.run {
246
+ let data: [String: Any] = [
247
+ "type": result.appUpdate != nil ? "app_update" : "live_update",
248
+ "status": result.success ? "completed" : "failed",
249
+ "percent": 100
250
+ ]
251
+ self.eventListener?("backgroundUpdateProgress", data)
252
+ }
253
+
254
+ task.setTaskCompleted(success: result.success)
255
+ }
256
+ }
257
+
258
+ private func performBackgroundCheck() async -> BackgroundCheckResult {
259
+ guard let config = backgroundUpdateConfig, config.enabled else {
260
+ return BackgroundCheckResult(
261
+ success: false,
262
+ updatesFound: false,
263
+ appUpdate: nil,
264
+ liveUpdate: nil,
265
+ notificationSent: false,
266
+ error: UpdateError(code: "INVALID_CONFIG", message: "Background updates not enabled")
267
+ )
268
+ }
269
+
270
+ backgroundUpdateStatus.isRunning = true
271
+ backgroundUpdateStatus.checkCount += 1
272
+ backgroundUpdateStatus.lastCheckTime = Int(Date().timeIntervalSince1970 * 1000)
273
+
274
+ var appUpdate: AppUpdateInfo?
275
+ var liveUpdate: LatestVersion?
276
+
277
+ // Check for app updates
278
+ if config.updateTypes.contains(.appUpdate) || config.updateTypes.contains(.both) {
279
+ appUpdate = await checkForAppUpdate()
280
+ }
281
+
282
+ // Check for live updates
283
+ if config.updateTypes.contains(.liveUpdate) || config.updateTypes.contains(.both) {
284
+ liveUpdate = await checkForLiveUpdate()
285
+ }
286
+
287
+ let updatesFound = (appUpdate?.updateAvailable ?? false) || (liveUpdate?.available ?? false)
288
+ var notificationSent = false
289
+
290
+ if updatesFound {
291
+ notificationSent = await sendNotification(appUpdate: appUpdate, liveUpdate: liveUpdate)
292
+ }
293
+
294
+ backgroundUpdateStatus.isRunning = false
295
+ backgroundUpdateStatus.lastError = nil
296
+
297
+ if updatesFound {
298
+ backgroundUpdateStatus.lastUpdateTime = Int(Date().timeIntervalSince1970 * 1000)
299
+ }
300
+
301
+ return BackgroundCheckResult(
302
+ success: true,
303
+ updatesFound: updatesFound,
304
+ appUpdate: appUpdate,
305
+ liveUpdate: liveUpdate,
306
+ notificationSent: notificationSent,
307
+ error: nil
308
+ )
309
+ }
310
+
311
+ private func checkForAppUpdate() async -> AppUpdateInfo? {
312
+ await appUpdateProvider?()
313
+ }
314
+
315
+ private func checkForLiveUpdate() async -> LatestVersion? {
316
+ await liveUpdateProvider?()
317
+ }
318
+
319
+ private func sendNotification(appUpdate: AppUpdateInfo?, liveUpdate: LatestVersion?) async -> Bool {
320
+ guard let notificationManager = notificationManager else {
321
+ return false
322
+ }
323
+
324
+ return await notificationManager.sendUpdateNotification(
325
+ appUpdate: appUpdate,
326
+ liveUpdate: liveUpdate
327
+ )
328
+ }
329
+ }
330
+
331
+ // MARK: - Data Models
332
+
333
+ struct BackgroundUpdateConfig {
334
+ let enabled: Bool
335
+ let checkInterval: Int
336
+ let updateTypes: [BackgroundUpdateType]
337
+ let autoInstall: Bool
338
+ let notificationPreferences: NotificationPreferences?
339
+ let respectBatteryOptimization: Bool
340
+ let allowMeteredConnection: Bool
341
+ let minimumBatteryLevel: Int
342
+ let requireWifi: Bool
343
+ let maxRetries: Int
344
+ let retryDelay: Int
345
+ let taskIdentifier: String?
346
+
347
+ static func from(_ obj: [String: Any]) throws -> BackgroundUpdateConfig {
348
+ guard let enabled = obj["enabled"] as? Bool,
349
+ let checkInterval = obj["checkInterval"] as? Int,
350
+ let updateTypesArray = obj["updateTypes"] as? [String] else {
351
+ throw NSError(domain: "BackgroundUpdateConfig", code: 1, userInfo: [NSLocalizedDescriptionKey: "Missing required fields"])
352
+ }
353
+
354
+ let updateTypes = updateTypesArray.compactMap { BackgroundUpdateType(rawValue: $0) }
355
+ let notificationPreferences = obj["notificationPreferences"] as? [String: Any]
356
+
357
+ return BackgroundUpdateConfig(
358
+ enabled: enabled,
359
+ checkInterval: checkInterval,
360
+ updateTypes: updateTypes,
361
+ autoInstall: obj["autoInstall"] as? Bool ?? false,
362
+ notificationPreferences: notificationPreferences != nil ? NotificationPreferences.from(notificationPreferences!) : nil,
363
+ respectBatteryOptimization: obj["respectBatteryOptimization"] as? Bool ?? true,
364
+ allowMeteredConnection: obj["allowMeteredConnection"] as? Bool ?? false,
365
+ minimumBatteryLevel: obj["minimumBatteryLevel"] as? Int ?? 20,
366
+ requireWifi: obj["requireWifi"] as? Bool ?? false,
367
+ maxRetries: obj["maxRetries"] as? Int ?? 3,
368
+ retryDelay: obj["retryDelay"] as? Int ?? 5000,
369
+ taskIdentifier: obj["taskIdentifier"] as? String
370
+ )
371
+ }
372
+ }
373
+
374
+ enum BackgroundUpdateType: String, CaseIterable {
375
+ case appUpdate = "app_update"
376
+ case liveUpdate = "live_update"
377
+ case both = "both"
378
+ }
379
+
380
+ struct BackgroundUpdateStatus {
381
+ var enabled: Bool
382
+ var lastCheckTime: Int?
383
+ var nextCheckTime: Int?
384
+ var lastUpdateTime: Int?
385
+ var currentTaskId: String?
386
+ var isRunning: Bool
387
+ var checkCount: Int
388
+ var failureCount: Int
389
+ var lastError: UpdateError?
390
+
391
+ func toDictionary() -> [String: Any] {
392
+ var obj: [String: Any] = [
393
+ "enabled": enabled,
394
+ "isRunning": isRunning,
395
+ "checkCount": checkCount,
396
+ "failureCount": failureCount
397
+ ]
398
+
399
+ if let lastCheckTime = lastCheckTime {
400
+ obj["lastCheckTime"] = lastCheckTime
401
+ }
402
+
403
+ if let nextCheckTime = nextCheckTime {
404
+ obj["nextCheckTime"] = nextCheckTime
405
+ }
406
+
407
+ if let lastUpdateTime = lastUpdateTime {
408
+ obj["lastUpdateTime"] = lastUpdateTime
409
+ }
410
+
411
+ if let currentTaskId = currentTaskId {
412
+ obj["currentTaskId"] = currentTaskId
413
+ }
414
+
415
+ if let lastError = lastError {
416
+ obj["lastError"] = lastError.toDictionary()
417
+ }
418
+
419
+ return obj
420
+ }
421
+ }
422
+
423
+ struct BackgroundCheckResult {
424
+ let success: Bool
425
+ let updatesFound: Bool
426
+ let appUpdate: AppUpdateInfo?
427
+ let liveUpdate: LatestVersion?
428
+ let notificationSent: Bool
429
+ let error: UpdateError?
430
+
431
+ func toDictionary() -> [String: Any] {
432
+ var obj: [String: Any] = [
433
+ "success": success,
434
+ "updatesFound": updatesFound,
435
+ "notificationSent": notificationSent
436
+ ]
437
+
438
+ if let appUpdate = appUpdate {
439
+ obj["appUpdate"] = appUpdate.toDictionary()
440
+ }
441
+
442
+ if let liveUpdate = liveUpdate {
443
+ obj["liveUpdate"] = liveUpdate.toDictionary()
444
+ }
445
+
446
+ if let error = error {
447
+ obj["error"] = error.toDictionary()
448
+ }
449
+
450
+ return obj
451
+ }
452
+ }
453
+
454
+ struct UpdateError {
455
+ let code: String
456
+ let message: String
457
+
458
+ func toDictionary() -> [String: Any] {
459
+ return [
460
+ "code": code,
461
+ "message": message
462
+ ]
463
+ }
464
+ }
@@ -0,0 +1,43 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
+ <plist version="1.0">
4
+ <dict>
5
+ <key>CFBundleDevelopmentRegion</key>
6
+ <string>$(DEVELOPMENT_LANGUAGE)</string>
7
+ <key>CFBundleExecutable</key>
8
+ <string>$(EXECUTABLE_NAME)</string>
9
+ <key>CFBundleIdentifier</key>
10
+ <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11
+ <key>CFBundleInfoDictionaryVersion</key>
12
+ <string>6.0</string>
13
+ <key>CFBundleName</key>
14
+ <string>$(PRODUCT_NAME)</string>
15
+ <key>CFBundlePackageType</key>
16
+ <string>FMWK</string>
17
+ <key>CFBundleShortVersionString</key>
18
+ <string>1.0</string>
19
+ <key>CFBundleVersion</key>
20
+ <string>1</string>
21
+ <key>NSAppTransportSecurity</key>
22
+ <dict>
23
+ <key>NSAllowsArbitraryLoads</key>
24
+ <false/>
25
+ <key>NSAllowsArbitraryLoadsForMedia</key>
26
+ <false/>
27
+ <key>NSAllowsArbitraryLoadsInWebContent</key>
28
+ <false/>
29
+ <key>NSAllowsLocalNetworking</key>
30
+ <false/>
31
+ </dict>
32
+ <key>UIBackgroundModes</key>
33
+ <array>
34
+ <string>background-app-refresh</string>
35
+ <string>background-processing</string>
36
+ </array>
37
+ <key>BGTaskSchedulerPermittedIdentifiers</key>
38
+ <array>
39
+ <string>com.aoneahsan.nativeupdate.background</string>
40
+ <string>com.aoneahsan.nativeupdate.processing</string>
41
+ </array>
42
+ </dict>
43
+ </plist>