mirror of
https://github.com/zhigang1992/react-native-code-push.git
synced 2026-06-10 07:10:36 +08:00
docs
This commit is contained in:
@@ -265,7 +265,7 @@ The `RemotePackage` inherits all of the same properties as the `LocalPackage`, b
|
||||
- __downloadUrl__: The URL at which the package is available for download. (String). This property is only needed for advanced usage, since the `download` method will automatically handle the acquisition of updates for you.
|
||||
|
||||
##### Methods
|
||||
- __download(progressHandler): Promise<LocalPackage>__: Downloads the package update from the CodePush service. If a `progressHandler` is specified, it will be called periodically with an object (`{ totalBytes: Number, receivedBytes: Number }`) that reports the progress of the download till the download completes. Returns a Promise that resolves with the `LocalPackage`.
|
||||
- __download(progressHandler?: Function): Promise<LocalPackage>__: Downloads the package update from the CodePush service. If a `progressHandler` is specified, it will be called periodically with an object (`{ totalBytes: Number, receivedBytes: Number }`) that reports the progress of the download till the download completes. Returns a Promise that resolves with the `LocalPackage`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -11,21 +11,24 @@ module.exports = (NativeCodePush) => {
|
||||
return Promise.reject(new Error("Cannot download an update without a download url"));
|
||||
}
|
||||
|
||||
// Use event subscription to obtain download progress.
|
||||
var downloadProgressSubscription = NativeAppEventEmitter.addListener(
|
||||
'CodePushDownloadProgress',
|
||||
progressHandler
|
||||
);
|
||||
var downloadProgressSubscription;
|
||||
if (progressHandler) {
|
||||
// Use event subscription to obtain download progress.
|
||||
downloadProgressSubscription = NativeAppEventEmitter.addListener(
|
||||
'CodePushDownloadProgress',
|
||||
progressHandler
|
||||
);
|
||||
}
|
||||
|
||||
// Use the downloaded package info. Native code will save the package info
|
||||
// so that the client knows what the current package version is.
|
||||
return NativeCodePush.downloadUpdate(this)
|
||||
.then((downloadedPackage) => {
|
||||
downloadProgressSubscription.remove();
|
||||
downloadProgressSubscription && downloadProgressSubscription.remove();
|
||||
return extend({}, downloadedPackage, local);
|
||||
})
|
||||
.catch((error) => {
|
||||
downloadProgressSubscription.remove();
|
||||
downloadProgressSubscription && downloadProgressSubscription.remove();
|
||||
// Rethrow the error for subsequent handlers down the promise chain.
|
||||
throw error;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user