native-update 1.0.3 → 1.0.4
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/docs/APP_REVIEW_GUIDE.md +1 -1
- package/docs/LIVE_UPDATES_GUIDE.md +35 -35
- package/docs/MIGRATION.md +1 -1
- package/docs/NATIVE_UPDATES_GUIDE.md +8 -8
- package/docs/QUICK_START.md +41 -52
- package/docs/README.md +4 -5
- package/docs/api/app-update-api.md +18 -110
- package/docs/api/events-api.md +83 -334
- package/docs/api/live-update-api.md +35 -66
- package/docs/examples/advanced-scenarios.md +54 -84
- package/docs/examples/basic-usage.md +40 -38
- package/docs/guides/migration-from-codepush.md +9 -10
- package/docs/guides/testing-guide.md +26 -27
- package/package.json +1 -1
package/docs/APP_REVIEW_GUIDE.md
CHANGED
|
@@ -764,5 +764,5 @@ Key takeaways for implementing app reviews:
|
|
|
764
764
|
## Next Steps
|
|
765
765
|
|
|
766
766
|
- Review the [Quick Start Guide](./QUICK_START.md)
|
|
767
|
-
- Check the [API Reference](
|
|
767
|
+
- Check the [API Reference](./api/app-review-api.md)
|
|
768
768
|
- See [Example Implementation](../example/src/services/review.service.ts)
|
|
@@ -127,25 +127,25 @@ import { NativeUpdate } from 'native-update';
|
|
|
127
127
|
export class UpdateManager {
|
|
128
128
|
async checkAndUpdate() {
|
|
129
129
|
try {
|
|
130
|
-
//
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
130
|
+
// Sync with the update server
|
|
131
|
+
const result = await NativeUpdate.sync();
|
|
132
|
+
|
|
133
|
+
switch (result.status) {
|
|
134
|
+
case 'UPDATE_AVAILABLE':
|
|
135
|
+
console.log(`Update available: ${result.bundle?.version}`);
|
|
136
|
+
// Update will be downloaded automatically by sync
|
|
137
|
+
break;
|
|
138
|
+
case 'UPDATE_INSTALLED':
|
|
139
|
+
console.log(`Update installed: ${result.bundle?.version}`);
|
|
140
|
+
// Reload the app to apply the update
|
|
141
|
+
await NativeUpdate.reload();
|
|
142
|
+
break;
|
|
143
|
+
case 'UP_TO_DATE':
|
|
144
|
+
console.log('App is up to date');
|
|
145
|
+
break;
|
|
146
|
+
case 'ERROR':
|
|
147
|
+
console.error('Update error:', result.error);
|
|
148
|
+
break;
|
|
149
149
|
}
|
|
150
150
|
} catch (error) {
|
|
151
151
|
console.error('Update failed:', error);
|
|
@@ -169,7 +169,7 @@ export class UpdateService {
|
|
|
169
169
|
async checkForUpdates(silent = false) {
|
|
170
170
|
try {
|
|
171
171
|
const { available, version, mandatory, notes } =
|
|
172
|
-
await NativeUpdate.
|
|
172
|
+
await NativeUpdate.sync();
|
|
173
173
|
|
|
174
174
|
if (!available) {
|
|
175
175
|
if (!silent) {
|
|
@@ -220,7 +220,7 @@ export class UpdateService {
|
|
|
220
220
|
|
|
221
221
|
try {
|
|
222
222
|
// Download with progress
|
|
223
|
-
await NativeUpdate.
|
|
223
|
+
await NativeUpdate.download({
|
|
224
224
|
onProgress: (progress) => {
|
|
225
225
|
loading.message = `Downloading... ${Math.round(progress.percent)}%`;
|
|
226
226
|
},
|
|
@@ -229,7 +229,7 @@ export class UpdateService {
|
|
|
229
229
|
loading.message = 'Applying update...';
|
|
230
230
|
|
|
231
231
|
// Apply the update
|
|
232
|
-
await NativeUpdate.
|
|
232
|
+
await NativeUpdate.reload();
|
|
233
233
|
|
|
234
234
|
// The app will restart automatically
|
|
235
235
|
} catch (error) {
|
|
@@ -291,18 +291,18 @@ export class AppComponent implements OnInit {
|
|
|
291
291
|
export class UpdateStrategies {
|
|
292
292
|
// Immediate update (default)
|
|
293
293
|
async immediateUpdate() {
|
|
294
|
-
const { available } = await NativeUpdate.
|
|
294
|
+
const { available } = await NativeUpdate.sync();
|
|
295
295
|
if (available) {
|
|
296
|
-
await NativeUpdate.
|
|
297
|
-
await NativeUpdate.
|
|
296
|
+
await NativeUpdate.download();
|
|
297
|
+
await NativeUpdate.reload(); // Restarts immediately
|
|
298
298
|
}
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
// Update on next restart
|
|
302
302
|
async updateOnRestart() {
|
|
303
|
-
const { available } = await NativeUpdate.
|
|
303
|
+
const { available } = await NativeUpdate.sync();
|
|
304
304
|
if (available) {
|
|
305
|
-
await NativeUpdate.
|
|
305
|
+
await NativeUpdate.download();
|
|
306
306
|
await NativeUpdate.applyUpdate({
|
|
307
307
|
reloadStrategy: 'on-next-restart',
|
|
308
308
|
});
|
|
@@ -312,14 +312,14 @@ export class UpdateStrategies {
|
|
|
312
312
|
|
|
313
313
|
// Update with confirmation
|
|
314
314
|
async updateWithConfirmation() {
|
|
315
|
-
const { available } = await NativeUpdate.
|
|
315
|
+
const { available } = await NativeUpdate.sync();
|
|
316
316
|
if (available) {
|
|
317
|
-
await NativeUpdate.
|
|
317
|
+
await NativeUpdate.download();
|
|
318
318
|
|
|
319
319
|
// Show confirmation dialog
|
|
320
320
|
const confirmed = await this.showUpdateReadyDialog();
|
|
321
321
|
if (confirmed) {
|
|
322
|
-
await NativeUpdate.
|
|
322
|
+
await NativeUpdate.reload();
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
}
|
|
@@ -444,7 +444,7 @@ const { versions } = await NativeUpdate.getVersions();
|
|
|
444
444
|
|
|
445
445
|
// Rollback to previous version
|
|
446
446
|
if (versions.length > 1) {
|
|
447
|
-
await NativeUpdate.
|
|
447
|
+
await NativeUpdate.reset();
|
|
448
448
|
}
|
|
449
449
|
|
|
450
450
|
// Rollback to specific version
|
|
@@ -482,7 +482,7 @@ await NativeUpdate.configure({
|
|
|
482
482
|
class CustomUpdateUI {
|
|
483
483
|
async showUpdateFlow() {
|
|
484
484
|
// Custom check
|
|
485
|
-
const update = await NativeUpdate.
|
|
485
|
+
const update = await NativeUpdate.sync();
|
|
486
486
|
|
|
487
487
|
if (update.available) {
|
|
488
488
|
// Show custom UI
|
|
@@ -519,7 +519,7 @@ const skipVersions = ['1.0.2', '1.0.3']; // Known bad versions
|
|
|
519
519
|
class RobustUpdateManager {
|
|
520
520
|
async safeUpdate() {
|
|
521
521
|
try {
|
|
522
|
-
await NativeUpdate.
|
|
522
|
+
await NativeUpdate.sync();
|
|
523
523
|
} catch (error) {
|
|
524
524
|
if (error.code === 'NETWORK_ERROR') {
|
|
525
525
|
// Retry with exponential backoff
|
|
@@ -561,7 +561,7 @@ await NativeUpdate.setChannel({
|
|
|
561
561
|
// Download during off-peak hours
|
|
562
562
|
const now = new Date().getHours();
|
|
563
563
|
if (now >= 2 && now <= 6) {
|
|
564
|
-
await NativeUpdate.
|
|
564
|
+
await NativeUpdate.download({
|
|
565
565
|
priority: 'low',
|
|
566
566
|
});
|
|
567
567
|
}
|
|
@@ -646,5 +646,5 @@ console.log('Update system health:', {
|
|
|
646
646
|
|
|
647
647
|
- Read the [Native App Updates Guide](./NATIVE_UPDATES_GUIDE.md)
|
|
648
648
|
- Learn about [App Review Integration](./APP_REVIEW_GUIDE.md)
|
|
649
|
-
- Check out [Security Best Practices](./
|
|
649
|
+
- Check out [Security Best Practices](./guides/security-best-practices.md)
|
|
650
650
|
- See [Bundle Signing Documentation](./BUNDLE_SIGNING.md)
|
package/docs/MIGRATION.md
CHANGED
|
@@ -188,5 +188,5 @@ await NativeUpdate.configure(config);
|
|
|
188
188
|
### Getting Help
|
|
189
189
|
|
|
190
190
|
- Check our [example app](../example) for implementation patterns
|
|
191
|
-
- Review the [API documentation](
|
|
191
|
+
- Review the [API documentation](./api/live-update-api.md)
|
|
192
192
|
- File issues on GitHub for migration problems
|
|
@@ -113,7 +113,7 @@ export class NativeUpdateService {
|
|
|
113
113
|
const platform = Capacitor.getPlatform();
|
|
114
114
|
|
|
115
115
|
// Check for native app updates
|
|
116
|
-
const result = await NativeUpdate.
|
|
116
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
117
117
|
|
|
118
118
|
if (result.updateAvailable) {
|
|
119
119
|
console.log(`Update available: ${result.availableVersion}`);
|
|
@@ -144,7 +144,7 @@ export class AndroidImmediateUpdate {
|
|
|
144
144
|
async performImmediateUpdate() {
|
|
145
145
|
try {
|
|
146
146
|
// Start immediate update
|
|
147
|
-
const { started } = await NativeUpdate.
|
|
147
|
+
const { started } = await NativeUpdate.performImmediateUpdate();
|
|
148
148
|
|
|
149
149
|
if (started) {
|
|
150
150
|
// The app will be restarted automatically after update
|
|
@@ -261,7 +261,7 @@ export class AndroidFlexibleUpdate {
|
|
|
261
261
|
export class iOSAppStoreUpdate {
|
|
262
262
|
async checkAndPromptUpdate() {
|
|
263
263
|
try {
|
|
264
|
-
const result = await NativeUpdate.
|
|
264
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
265
265
|
|
|
266
266
|
if (result.updateAvailable) {
|
|
267
267
|
await this.showiOSUpdateDialog(result);
|
|
@@ -314,7 +314,7 @@ export class UnifiedUpdateService {
|
|
|
314
314
|
|
|
315
315
|
async checkAndUpdateApp() {
|
|
316
316
|
try {
|
|
317
|
-
const updateInfo = await NativeUpdate.
|
|
317
|
+
const updateInfo = await NativeUpdate.getAppUpdateInfo();
|
|
318
318
|
|
|
319
319
|
if (!updateInfo.updateAvailable) {
|
|
320
320
|
console.log('App is up to date');
|
|
@@ -534,7 +534,7 @@ export class UpdateUIService {
|
|
|
534
534
|
```typescript
|
|
535
535
|
export class SmartUpdateScheduler {
|
|
536
536
|
async scheduleUpdate() {
|
|
537
|
-
const updateInfo = await NativeUpdate.
|
|
537
|
+
const updateInfo = await NativeUpdate.getAppUpdateInfo();
|
|
538
538
|
|
|
539
539
|
if (!updateInfo.updateAvailable) return;
|
|
540
540
|
|
|
@@ -643,7 +643,7 @@ const state = await NativeUpdate.getUpdateState();
|
|
|
643
643
|
if (state.status === 'FAILED') {
|
|
644
644
|
// Clear update data and retry
|
|
645
645
|
await NativeUpdate.clearUpdateData();
|
|
646
|
-
await NativeUpdate.
|
|
646
|
+
await NativeUpdate.getAppUpdateInfo();
|
|
647
647
|
}
|
|
648
648
|
```
|
|
649
649
|
|
|
@@ -690,5 +690,5 @@ if (!config.appStoreId) {
|
|
|
690
690
|
|
|
691
691
|
- Learn about [Live Updates (OTA)](./LIVE_UPDATES_GUIDE.md)
|
|
692
692
|
- Implement [App Review Features](./APP_REVIEW_GUIDE.md)
|
|
693
|
-
- Review [Security Guidelines](./
|
|
694
|
-
- Check [API Reference](
|
|
693
|
+
- Review [Security Guidelines](./guides/security-best-practices.md)
|
|
694
|
+
- Check [API Reference](./api/app-update-api.md)
|
package/docs/QUICK_START.md
CHANGED
|
@@ -70,26 +70,19 @@ import { NativeUpdate } from 'native-update';
|
|
|
70
70
|
export class LiveUpdateService {
|
|
71
71
|
async checkAndApplyUpdates() {
|
|
72
72
|
try {
|
|
73
|
-
// 1.
|
|
74
|
-
const
|
|
75
|
-
await NativeUpdate.checkForUpdate();
|
|
73
|
+
// 1. Sync with the update server
|
|
74
|
+
const result = await NativeUpdate.sync();
|
|
76
75
|
|
|
77
|
-
if (
|
|
76
|
+
if (result.status === 'UP_TO_DATE') {
|
|
78
77
|
console.log('No updates available');
|
|
79
78
|
return;
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
console.log(`Download: ${progress.percent}%`);
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// 3. Apply the update (app will restart)
|
|
92
|
-
await NativeUpdate.applyUpdate();
|
|
81
|
+
if (result.status === 'UPDATE_INSTALLED') {
|
|
82
|
+
console.log(`Update ${result.bundle?.version} installed!`);
|
|
83
|
+
// Reload to apply the update
|
|
84
|
+
await NativeUpdate.reload();
|
|
85
|
+
}
|
|
93
86
|
} catch (error) {
|
|
94
87
|
console.error('Update failed:', error);
|
|
95
88
|
}
|
|
@@ -107,42 +100,41 @@ export class UpdateUIService {
|
|
|
107
100
|
) {}
|
|
108
101
|
|
|
109
102
|
async checkForUpdatesWithUI() {
|
|
110
|
-
const
|
|
111
|
-
await NativeUpdate.checkForUpdate();
|
|
103
|
+
const result = await NativeUpdate.sync();
|
|
112
104
|
|
|
113
|
-
if (
|
|
105
|
+
if (result.status === 'UP_TO_DATE') return;
|
|
114
106
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
107
|
+
if (result.status === 'UPDATE_AVAILABLE') {
|
|
108
|
+
// Show update dialog
|
|
109
|
+
const alert = await this.alertController.create({
|
|
110
|
+
header: 'Update Available',
|
|
111
|
+
message: `Version ${result.bundle?.version} is ready!\n\nBug fixes and improvements`,
|
|
112
|
+
buttons: [
|
|
113
|
+
{ text: 'Later', role: 'cancel' },
|
|
114
|
+
{
|
|
115
|
+
text: 'Update Now',
|
|
116
|
+
handler: () => this.applyUpdate(),
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
});
|
|
127
120
|
|
|
128
|
-
|
|
121
|
+
await alert.present();
|
|
122
|
+
} else if (result.status === 'UPDATE_INSTALLED') {
|
|
123
|
+
// Update already installed, just need to reload
|
|
124
|
+
await NativeUpdate.reload();
|
|
125
|
+
}
|
|
129
126
|
}
|
|
130
127
|
|
|
131
|
-
private async
|
|
128
|
+
private async applyUpdate() {
|
|
132
129
|
const loading = await this.loadingController.create({
|
|
133
|
-
message: '
|
|
130
|
+
message: 'Applying update...',
|
|
134
131
|
});
|
|
135
132
|
await loading.present();
|
|
136
133
|
|
|
137
134
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
},
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
loading.message = 'Installing...';
|
|
145
|
-
await NativeUpdate.applyUpdate();
|
|
135
|
+
// The sync method already downloaded the update
|
|
136
|
+
// We just need to reload the app
|
|
137
|
+
await NativeUpdate.reload();
|
|
146
138
|
} catch (error) {
|
|
147
139
|
await loading.dismiss();
|
|
148
140
|
// Show error
|
|
@@ -179,7 +171,7 @@ Check for app store updates and install them!
|
|
|
179
171
|
export class NativeUpdateService {
|
|
180
172
|
async checkForAppStoreUpdates() {
|
|
181
173
|
try {
|
|
182
|
-
const result = await NativeUpdate.
|
|
174
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
183
175
|
|
|
184
176
|
if (!result.updateAvailable) {
|
|
185
177
|
console.log('App is up to date');
|
|
@@ -200,7 +192,7 @@ export class NativeUpdateService {
|
|
|
200
192
|
private async handleAndroidUpdate(result: any) {
|
|
201
193
|
if (result.immediateUpdateAllowed) {
|
|
202
194
|
// Critical update - must install
|
|
203
|
-
await NativeUpdate.
|
|
195
|
+
await NativeUpdate.performImmediateUpdate();
|
|
204
196
|
} else {
|
|
205
197
|
// Optional update - download in background
|
|
206
198
|
await NativeUpdate.startFlexibleUpdate();
|
|
@@ -422,12 +414,9 @@ export class AppComponent implements OnInit {
|
|
|
422
414
|
// Live Updates
|
|
423
415
|
private async checkLiveUpdates() {
|
|
424
416
|
try {
|
|
425
|
-
const
|
|
426
|
-
|
|
427
|
-
if (available) {
|
|
428
|
-
// Auto-download in background
|
|
429
|
-
await NativeUpdate.downloadUpdate();
|
|
417
|
+
const result = await NativeUpdate.sync();
|
|
430
418
|
|
|
419
|
+
if (result.status === 'UPDATE_INSTALLED') {
|
|
431
420
|
// Notify user
|
|
432
421
|
const toast = await this.toastCtrl.create({
|
|
433
422
|
message: 'Update ready! Restart to apply.',
|
|
@@ -435,7 +424,7 @@ export class AppComponent implements OnInit {
|
|
|
435
424
|
buttons: [
|
|
436
425
|
{
|
|
437
426
|
text: 'Restart',
|
|
438
|
-
handler: () => NativeUpdate.
|
|
427
|
+
handler: () => NativeUpdate.reload(),
|
|
439
428
|
},
|
|
440
429
|
],
|
|
441
430
|
});
|
|
@@ -462,7 +451,7 @@ export class AppComponent implements OnInit {
|
|
|
462
451
|
|
|
463
452
|
private async checkNativeUpdates() {
|
|
464
453
|
try {
|
|
465
|
-
const result = await NativeUpdate.
|
|
454
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
466
455
|
|
|
467
456
|
if (result.updateAvailable && result.flexibleUpdateAllowed) {
|
|
468
457
|
// Start background download for Android
|
|
@@ -569,8 +558,8 @@ Now that you have the basics working:
|
|
|
569
558
|
- [Live Updates Guide](./LIVE_UPDATES_GUIDE.md) - Complete OTA implementation
|
|
570
559
|
- [Native Updates Guide](./NATIVE_UPDATES_GUIDE.md) - Platform-specific details
|
|
571
560
|
- [App Review Guide](./APP_REVIEW_GUIDE.md) - Maximize review rates
|
|
572
|
-
- [Security Guide](./
|
|
573
|
-
- [API Reference](
|
|
561
|
+
- [Security Guide](./guides/security-best-practices.md) - Best practices
|
|
562
|
+
- [API Reference](./api/live-update-api.md) - All methods and options
|
|
574
563
|
|
|
575
564
|
## Troubleshooting
|
|
576
565
|
|
package/docs/README.md
CHANGED
|
@@ -7,7 +7,6 @@
|
|
|
7
7
|
> - Bundle storage and CDN
|
|
8
8
|
> - Signing and security services
|
|
9
9
|
>
|
|
10
|
-
> See [ROADMAP.md](../ROADMAP.md) for complete requirements.
|
|
11
10
|
|
|
12
11
|
Welcome to the comprehensive documentation for **Capacitor Native Update**, a foundation plugin that provides architecture for a complete update lifecycle management solution for Capacitor applications.
|
|
13
12
|
|
|
@@ -34,8 +33,9 @@ Created by **Ahsan Mahmood** and open-sourced for the developer community, this
|
|
|
34
33
|
### Guides
|
|
35
34
|
|
|
36
35
|
- [**Security Best Practices**](./guides/security-best-practices.md) - Implement secure updates
|
|
37
|
-
- [**Migration
|
|
38
|
-
- [**
|
|
36
|
+
- [**Migration from CodePush**](./guides/migration-from-codepush.md) - Migrate from CodePush
|
|
37
|
+
- [**Testing Guide**](./guides/testing-guide.md) - Testing your update implementation
|
|
38
|
+
- [**Deployment Guide**](./guides/deployment-guide.md) - Deploy to production
|
|
39
39
|
|
|
40
40
|
### API Reference
|
|
41
41
|
|
|
@@ -47,8 +47,7 @@ Created by **Ahsan Mahmood** and open-sourced for the developer community, this
|
|
|
47
47
|
### Examples
|
|
48
48
|
|
|
49
49
|
- [**Basic Usage**](./examples/basic-usage.md) - Simple implementation examples
|
|
50
|
-
- [**Advanced Scenarios**](./examples/advanced-scenarios.md) - Complex use cases
|
|
51
|
-
- [**Integration Examples**](./examples/integration-examples.md) - Framework-specific integrations
|
|
50
|
+
- [**Advanced Scenarios**](./examples/advanced-scenarios.md) - Complex use cases and framework integrations
|
|
52
51
|
|
|
53
52
|
### Production
|
|
54
53
|
|
|
@@ -4,12 +4,12 @@ Complete API documentation for native app store update functionality.
|
|
|
4
4
|
|
|
5
5
|
## Methods
|
|
6
6
|
|
|
7
|
-
###
|
|
7
|
+
### getAppUpdateInfo()
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Get information about available app updates in the app store.
|
|
10
10
|
|
|
11
11
|
```typescript
|
|
12
|
-
const result = await NativeUpdate.
|
|
12
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
13
13
|
// Returns:
|
|
14
14
|
{
|
|
15
15
|
updateAvailable: boolean;
|
|
@@ -29,13 +29,13 @@ const result = await NativeUpdate.checkAppUpdate();
|
|
|
29
29
|
}
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
-
###
|
|
32
|
+
### performImmediateUpdate()
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
Perform an immediate (blocking) update. Android only - shows full-screen update UI.
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
try {
|
|
38
|
-
await NativeUpdate.
|
|
38
|
+
await NativeUpdate.performImmediateUpdate();
|
|
39
39
|
// App will restart after update
|
|
40
40
|
} catch (error) {
|
|
41
41
|
// User cancelled or update failed
|
|
@@ -60,105 +60,20 @@ await NativeUpdate.completeFlexibleUpdate();
|
|
|
60
60
|
// App will restart
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
-
### getVersionInfo()
|
|
64
|
-
|
|
65
|
-
Get detailed version information.
|
|
66
|
-
|
|
67
|
-
```typescript
|
|
68
|
-
const info = await NativeUpdate.getVersionInfo();
|
|
69
|
-
// Returns:
|
|
70
|
-
{
|
|
71
|
-
currentVersion: string; // e.g., "1.2.3"
|
|
72
|
-
buildNumber: string; // e.g., "123"
|
|
73
|
-
packageName: string; // e.g., "com.example.app"
|
|
74
|
-
platform: 'ios' | 'android' | 'web';
|
|
75
|
-
availableVersion?: string; // From app store
|
|
76
|
-
minimumVersion?: string; // Minimum required version
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### isMinimumVersionMet()
|
|
81
|
-
|
|
82
|
-
Check if the app meets minimum version requirements.
|
|
83
|
-
|
|
84
|
-
```typescript
|
|
85
|
-
const result = await NativeUpdate.isMinimumVersionMet();
|
|
86
|
-
// Returns:
|
|
87
|
-
{
|
|
88
|
-
isMet: boolean;
|
|
89
|
-
currentVersion: string;
|
|
90
|
-
minimumVersion: string;
|
|
91
|
-
updateRequired: boolean;
|
|
92
|
-
}
|
|
93
|
-
```
|
|
94
|
-
|
|
95
63
|
### openAppStore()
|
|
96
64
|
|
|
97
65
|
Open the app store page for updates.
|
|
98
66
|
|
|
99
67
|
```typescript
|
|
100
|
-
await NativeUpdate.openAppStore(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
### getAppStoreUrl()
|
|
104
|
-
|
|
105
|
-
Get the app store URL without opening it.
|
|
106
|
-
|
|
107
|
-
```typescript
|
|
108
|
-
const result = await NativeUpdate.getAppStoreUrl();
|
|
109
|
-
// Returns:
|
|
110
|
-
{
|
|
111
|
-
url: string; // e.g., "https://apps.apple.com/app/id123456789"
|
|
112
|
-
platform: 'ios' | 'android' | 'web';
|
|
113
|
-
}
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
### getUpdateInstallState()
|
|
117
|
-
|
|
118
|
-
Get the current install state of a flexible update. Android only.
|
|
119
|
-
|
|
120
|
-
```typescript
|
|
121
|
-
const state = await NativeUpdate.getUpdateInstallState();
|
|
122
|
-
// Returns:
|
|
123
|
-
{
|
|
124
|
-
installStatus: number; // Android InstallStatus code
|
|
125
|
-
bytesDownloaded: number;
|
|
126
|
-
totalBytesToDownload: number;
|
|
127
|
-
percentComplete: number;
|
|
128
|
-
}
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
## Events
|
|
132
|
-
|
|
133
|
-
### appUpdateStateChanged
|
|
134
|
-
|
|
135
|
-
Fired when app update state changes. Android only.
|
|
136
|
-
|
|
137
|
-
```typescript
|
|
138
|
-
NativeUpdate.addListener('appUpdateStateChanged', (state) => {
|
|
139
|
-
console.log('Install status:', state.installStatus);
|
|
140
|
-
// InstallStatus codes:
|
|
141
|
-
// 0: Unknown
|
|
142
|
-
// 1: Pending
|
|
143
|
-
// 2: Downloading
|
|
144
|
-
// 3: Installing
|
|
145
|
-
// 4: Installed
|
|
146
|
-
// 5: Failed
|
|
147
|
-
// 6: Canceled
|
|
148
|
-
// 11: Downloaded
|
|
68
|
+
await NativeUpdate.openAppStore({
|
|
69
|
+
// Optional: specify app ID for iOS or package name for Android
|
|
70
|
+
appId: 'your-app-id'
|
|
149
71
|
});
|
|
150
72
|
```
|
|
151
73
|
|
|
152
|
-
|
|
74
|
+
## Events
|
|
153
75
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
```typescript
|
|
157
|
-
NativeUpdate.addListener('appUpdateProgress', (progress) => {
|
|
158
|
-
console.log(`Downloaded: ${progress.bytesDownloaded}/${progress.totalBytesToDownload}`);
|
|
159
|
-
console.log(`Progress: ${progress.percentComplete}%`);
|
|
160
|
-
});
|
|
161
|
-
```
|
|
76
|
+
Note: App update events are not directly exposed. Instead, use the `updateStateChanged` and `downloadProgress` events from the Live Update API when performing app updates. The native update process on Android and iOS is handled by the platform's native update mechanisms.
|
|
162
77
|
|
|
163
78
|
## Platform Differences
|
|
164
79
|
|
|
@@ -200,9 +115,9 @@ NativeUpdate.addListener('appUpdateProgress', (progress) => {
|
|
|
200
115
|
1. **Check for updates on app start**
|
|
201
116
|
```typescript
|
|
202
117
|
async function checkOnStart() {
|
|
203
|
-
const result = await NativeUpdate.
|
|
118
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
204
119
|
if (result.updateAvailable && result.updatePriority === 'IMMEDIATE') {
|
|
205
|
-
await NativeUpdate.
|
|
120
|
+
await NativeUpdate.performImmediateUpdate();
|
|
206
121
|
}
|
|
207
122
|
}
|
|
208
123
|
```
|
|
@@ -212,23 +127,16 @@ NativeUpdate.addListener('appUpdateProgress', (progress) => {
|
|
|
212
127
|
// Start download
|
|
213
128
|
await NativeUpdate.startFlexibleUpdate();
|
|
214
129
|
|
|
215
|
-
//
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
// Complete when ready
|
|
221
|
-
const stateListener = NativeUpdate.addListener('appUpdateStateChanged', (state) => {
|
|
222
|
-
if (state.installStatus === 11) { // Downloaded
|
|
223
|
-
showUpdateReadyPrompt();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
130
|
+
// Note: Progress monitoring for native app updates is handled
|
|
131
|
+
// internally by the platform. For Android, the Play Core library
|
|
132
|
+
// shows its own UI. For custom progress tracking, use Live Updates
|
|
133
|
+
// instead of native app updates.
|
|
226
134
|
```
|
|
227
135
|
|
|
228
136
|
3. **Fallback for iOS**
|
|
229
137
|
```typescript
|
|
230
138
|
if (platform === 'ios') {
|
|
231
|
-
const result = await NativeUpdate.
|
|
139
|
+
const result = await NativeUpdate.getAppUpdateInfo();
|
|
232
140
|
if (result.updateAvailable) {
|
|
233
141
|
showUpdateDialog(() => {
|
|
234
142
|
NativeUpdate.openAppStore();
|