Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Swift Firebase Storage获取所有下载URL';某一特定儿童的特征_Ios_Swift_Firebase_Firebase Storage - Fatal编程技术网

Ios Swift Firebase Storage获取所有下载URL';某一特定儿童的特征

Ios Swift Firebase Storage获取所有下载URL';某一特定儿童的特征,ios,swift,firebase,firebase-storage,Ios,Swift,Firebase,Firebase Storage,目前,我可以通过firebase storage reference通过文件名获取下载url func getDownloadURL() { let ref = Storage.storage().reference() let fileName = "Lessons_Lesson1_Class1.mp3" let starsRef = ref.child("Daily Meditations").ch

目前,我可以通过firebase storage reference通过文件名获取下载url

func getDownloadURL() {
    
    let ref = Storage.storage().reference()
    
    let fileName = "Lessons_Lesson1_Class1.mp3"
    
    let starsRef = ref.child("Daily Meditations").child("Lessons").child("Lesson 1").child(fileName)
    

    // Fetch the download URL
    starsRef.downloadURL { url, error in
      if let error = error {
        // Handle any errors
        print(error)
      } else {
        // Get the download URL for 'Lessons_Lesson1_Class1.mp3'
        print(url)
      }
    }
   
    
}
我想检索特定子中的所有下载URL,而不使用文件名,只使用最后一个子名

只需在列表/数组中添加每个下载url

我如何通过我的参考资料来实现这一点

func getDownloadURL() {
    
    let ref = Storage.storage().reference()
    
    let fileName = "Lessons_Lesson1_Class1.mp3"
    
    let starsRef = ref.child("Daily Meditations").child("Lessons").child("Lesson 1").child(fileName)
    

    // Fetch the download URL
    starsRef.downloadURL { url, error in
      if let error = error {
        // Handle any errors
        print(error)
      } else {
        // Get the download URL for 'Lessons_Lesson1_Class1.mp3'
        print(url)
      }
    }
   
    
}

我假设路径名中允许使用空格,因为您正在使用它们。要列出路径中的所有文件,请使用
listAll
。该方法将返回一个我命名为
list
StorageListResult
对象


因此,我能够将列出所有文件下载URL结合起来,以实现我试图从firebase文档中实现的目标

代码如下:

func getDownloadURl() {
        
        let ref = Storage.storage().reference()
        
        let storageReference = ref.child("Lessons/Lesson 1")
        storageReference.listAll { (result, error) in
          if let error = error {
            print(error)
          }
        for item in result.items {
            //List storage reference
            let storageLocation = String(describing: item)
            let gsReference = Storage.storage().reference(forURL: storageLocation)
            
            // Fetch the download URL
            gsReference.downloadURL { url, error in
              if let error = error {
                // Handle any errors
                print(error)
              } else {
                // Get the download URL for each item storage location
                print(url!)
              }
            }
            
            
          }
        }
        
    }

似乎您希望使用列表文件API。所以我使用了列表文件,但结果给出了存储位置,而不是下载URL。谢谢@DougStevenson。我找到了一种方法,通过查看这两个文档来实现我所需要的。您必须为找到的每个文件调用getDownloadUrl一次。这只打印文件名。我确信有一种方法可以将文件名转换为URL,但我已经找到了一个有效的解决方案。非常感谢。