【问题标题】:How to continue download multiple files (AWS server images) in background in react-native iOS如何在 react-native iOS 的后台继续下载多个文件(AWS 服务器图像)
【发布时间】:2019-06-17 18:33:08
【问题描述】:

我创建了一个应用程序,用户可以使用在 Android 中完美运行的 react-native-fs 一键下载多个图像。但在 iOS 中,当应用处于非活动状态时,下载会停止,用户必须重新开始下载。

async.eachSeries(DownloadData, async function (tourData, finish) {
    console.log("# resumable : 655612", tourData);
    var fileExtension = '';
    var fileURL = tourData.path;
var fileExtension = "/" + tourData.name + "Image" + p + ".png
     p = p + 1;
    const downloadDest = RNFS.DocumentDirectoryPath + fileExtension;
    let dirs = RNFetchBlob.fs.dirs;
    var v = dirs.DocumentDir;
    var jobId = -1;

    const ret = RNFS.downloadFile({
        fromUrl: encodeURI(fileURL),
        toFile: downloadDest,
        connectionTimeout: 1000 * 10,
        readTimeout: 1000 * 10,
        background: true,
        discretionary: true,
        progressDivider: 1,
        resumable: (res) => {
            console.log("# resumable", res);
        },
        begin: (res) => {
         console.log(res)
        },
        progress: (data) => {
           console.log(data)
        },
    });

    jobId = ret.jobId;

    RNFS.isResumable(jobId).then(true);

    if (await RNFS.isResumable(jobId)) {
        console.log("# resumable : # resumable : # resumable :",jobId);
        RNFS.resumeDownload(jobId)
    }
    ret.promise.then((res) => {
       finish();
   }).catch(err => {
       finish();
   })

},函数(错误){ 如果(!错误){ 回调(真) } 别的 { 回调(假) } }));

【问题讨论】:

    标签: react-native react-native-android react-native-ios react-native-fs ios-background-mode


    【解决方案1】:

    在IOS后台运行下载需要一些额外的设置检查这个部分https://github.com/itinance/react-native-fs#background-downloads-tutorial-ios 他们还提到IOS会在handleEventsForBackgroundURLSession之后给你30秒

    BE AWARE! iOS will give about 30 sec. to run your code after handleEventsForBackgroundURLSession is called and until completionHandler is triggered so don't do anything that might take a long time (like unzipping), you will be able to do it after the user re-launces the app, otherwide iOS will terminate your app.

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2018-01-19
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 2014-05-07
      • 2012-06-21
      • 1970-01-01
      • 2013-05-29
      • 2020-12-27
      相关资源
      最近更新 更多