2016-09-15 66 views
0

我需要從Firebase數據庫加載圖片的幫助。我已將2張圖片上傳到Firebase。當我想要加載圖像。看起來這個錯誤如何在Firebase中使用writeToFile處理超出最大尺寸?

Attempeted to download object with size of 1050168 bytes, which exceeds the maximum size of 1048576 bytes. Consider raising the maximum download size, or using [FIRStorageReference writeToFile:] 

但是,有時我可以加載2張圖片,有時它會卡住。

我是Swift和Firebase的新手。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

    storageRef = FIRStorage.storage().referenceForURL(toDoList[indexPath.row].imageName) 
    let storageRef1 = FIRStorage.storage().referenceForURL(toDoList[indexPath.row].secondPhoto) 
    let itemSelected = toDoList[indexPath.row] 
    storageRef.dataWithMaxSize(1 * 1024 * 1024) { (data, error) in 
     if error == nil 
     { 
      dispatch_async(dispatch_get_main_queue(), { 
       if let data = data 
       { 
        storageRef1.dataWithMaxSize(1 * 1024 * 1024) { (data1, error) in 

         if error == nil 
         { 
          dispatch_async(dispatch_get_main_queue(), { 
           if let data1 = data1 
           { 
            let detailVC:DetailViewController = self.storyboard?.instantiateViewControllerWithIdentifier("DetailViewController") as! DetailViewController 
            print(itemSelected.eventID) 
            detailVC.eventIDfromDetail = itemSelected.eventID 
            detailVC.titleEvent = itemSelected.title 
            detailVC.staffEvent = itemSelected.staff 
            detailVC.locationEvent = itemSelected.location 
            detailVC.startEvent = itemSelected.starts 
            detailVC.endEvent = itemSelected.ends 
            detailVC.repeatEvent = itemSelected.rpeat 
            detailVC.imageDetail = UIImage(data: data)! 
            detailVC.descriptionDetail = itemSelected.description 
            detailVC.secondPhotoEvent = UIImage(data: data1)! 
            detailVC.key = itemSelected.key 
            detailVC.isFinish = itemSelected.isCompleted 
            self.presentViewController(detailVC, animated: true, completion: nil) 
           } 
          }) 
         } 
         else 
         { 
          print(error!.localizedDescription) 
         } 

        }} 
      }) 
     } 
     else 
     { 
      print(error!.localizedDescription) 
     } 

    } 
} 

回答

0

看起來你需要提高dataWithMaxSize。根據Firebase文檔,請注意,您不會下載超出設備內存容量的文件,否則應用程序會崩潰。指向Firebase Docs here的鏈接。