【问题标题】:How to show a downloading activity for firebase storage download如何显示 Firebase 存储下载的下载活动
【发布时间】:2017-04-25 07:48:51
【问题描述】:

我有一个可以上传和显示图片的应用。我发现当我不在wifi上时,下载图像需要一些时间。我想改进我的用户体验,所以我想在下载图像时有一个下载活动指示器。

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

[[[FIRStorage storage] referenceForURL:profileURL] dataWithMaxSize:INT64_MAX
                                                                        completion:^(NSData *data, NSError *error) {
                                                                            if (error) {
                                                                                NSLog(@"Error downloading: %@", error);
                                                                                return;
                                                                            }
                                                                            NSString *dataType=[self contentTypeForImageData:data];
                                                                            if (dataType) {
                                                                            [_imageCache setObject:[UIImage imageWithData:data] forKey:uid];
                                                                            }
                                                                            myIcon.image =
                                                                            [UIImage imageWithData:data];
                                                                        }];
            });

这就是我下载图像和缓存的方式。

【问题讨论】:

    标签: ios objective-c progress firebase-storage


    【解决方案1】:

    事情 1:不需要使用额外的队列,我们​​已经在后台线程上执行下载,所以它不会阻塞你的 UI。

    事情 2:你想做这样的事情:

    // Upload file and metadata to the object 'images/mountains.jpg'
    FIRStorageUploadTask *uploadTask = [storageRef putFile:localFile metadata:metadata];
    
    // Start the upload progress UI
    
    [uploadTask observeStatus:FIRStorageTaskStatusProgress handler:^(FIRStorageTaskSnapshot *snapshot) {
      // Update the progress UI with the progress
    }];
    
    [uploadTask observeStatus:FIRStorageTaskStatusSuccess handler:^(FIRStorageTaskSnapshot *snapshot) {
      // Remove the progress UI
    }];
    

    考虑使用MBProgressHub 作为您的微调器。

    【讨论】:

      猜你喜欢
      • 2018-08-09
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      • 2019-06-11
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 2020-01-31
      相关资源
      最近更新 更多