Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.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元数据!。下载URL()!。绝对字符串_Ios_Swift_Firebase_Firebase Storage - Fatal编程技术网

Ios Swift Firebase元数据!。下载URL()!。绝对字符串

Ios Swift Firebase元数据!。下载URL()!。绝对字符串,ios,swift,firebase,firebase-storage,Ios,Swift,Firebase,Firebase Storage,刚刚更新了我的可可豆,从而更新了firebase。这行代码是旧的方式,现在是错误的: let downloadURL = metaData!.downloadURL()!.absoluteString let values: Dictionary<String, Any> = ["download_url": downloadURL] 使用下面的答案… 当我使用下面提交的答案时,我会得到一个打印输出,上面写着“用户没有访问gs://shopper-e7270.appspot.com

刚刚更新了我的可可豆,从而更新了firebase。这行代码是旧的方式,现在是错误的:

let downloadURL = metaData!.downloadURL()!.absoluteString
let values: Dictionary<String, Any> = ["download_url": downloadURL]
使用下面的答案…

当我使用下面提交的答案时,我会得到一个打印输出,上面写着“用户没有访问gs://shopper-e7270.appspot.com/(null)的权限”。我所要做的就是获取URL字符串并将其添加到我的“值”中,这是一个字典

我上传图像和保存为孩子的完整代码

let databaseRef = Database.database().reference()
let path = databaseRef.child("posts").child((self.loggedInUser?.uid)!).childByAutoId()
path.setValue(values) { (error, ref) -> Void in
    if error != nil {
        print("error saving post in db")
    } else {
        let storageRef = Storage.storage().reference().child("posts_requests").child((self.loggedInUser?.uid)!).child(snapshot.childSnapshot(forPath: "uid").value as! String).child(snapshot.childSnapshot(forPath: "uid").value as! String).child(snapshot.childSnapshot(forPath: "imageID").value as! String)
        storageRef.delete(completion: { error in
            if let error = error {
                print(error)
            } else {
                print("Successful Delete")
            }
        })

    }
}
        let photosRef = storage.reference().child("posts").child((loggedInUser?.uid)!)
    let usersRef = Database.database().reference().child("Businesses")
    let databaseRef = Database.database().reference()
    let imageName = NSUUID().uuidString
    let photoRef = photosRef.child("\(uid)")
    let postID = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId().key
    var downloadURLSting = String()

    photoRef.child("\(imageName)").putData(data!, metadata: nil) { (metaData,error) in
        if let error = error {
            print("there was an error")
            print(error.localizedDescription)
            return
        } else {
            // store downloadURL
            storage.reference().downloadURL(completion: {(url, error) in
                if error != nil {
                    print(error!.localizedDescription)
                    return
                }
                let downloadURL = url?.absoluteString

                let values: Dictionary<String, Any> = ["uid": uid, "caption": caption ?? "", "download_url": downloadURL, "timestamp": ServerValue.timestamp(), "businessName":loggedInUserData?["businessName"] as! String, "businessStreet":loggedInUserData?["businessStreet"] as! String, "businessCity":loggedInUserData?["businessCity"] as! String, "businessState":loggedInUserData?["businessState"] as! String, "businessZIP":loggedInUserData?["businessZIP"] as! String, "businessPhone":loggedInUserData?["businessPhone"] as! String, "businessWebsite":loggedInUserData?["businessWebsite"] as! String, "businessLatitude":loggedInUserData?["businessLatitude"] as! String, "businessLongitude":loggedInUserData?["businessLongitude"] as! String, "facebookURL":loggedInUserData?["facebookURL"] as! String, "twitterURL":loggedInUserData?["twitterURL"] as! String, "instagramURL":loggedInUserData?["instagramURL"] as! String, "googleURL":loggedInUserData?["googleURL"] as! String, "yelpURL":loggedInUserData?["yelpURL"] as! String, "foursquareURL":loggedInUserData?["foursquareURL"] as! String, "snapchatURL":loggedInUserData?["snapchatURL"] as! String, "imageID": imageName, "postID": postID]

                // store downloadURL at database
                let databaseRef = Database.database().reference()
                let path = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId()
                path.setValue(values) { (error, ref) -> Void in
                    if error != nil {
                        print("error saving post in db")
                    } else {
                        // reset caption field
                        self.descriptionTextView.text = ""
                        // reset placeholder image
                        self.imageView.image = UIImage(named: "filterPlaceholder")
                        MBProgressHUD.hide(for: self.view, animated: true)
                        let viewConrolller = self.storyboard?.instantiateViewController(withIdentifier: "Business Profile") as! UITabBarController
                        self.present(viewConrolller, animated: true, completion: nil)
                    }
                }
            })
        }
    }
let photoref=storage.reference().child(“posts”).child((loggedInUser?.uid)!)
让usersRef=Database.Database().reference().child(“业务”)
让databaseRef=Database.Database().reference()
让imageName=nsuid().uuidString
让photoRef=photoRef.child(“\(uid)”)
让postID=databaseRef.child(“posts”).child((loggedInUser?.uid)!).childByAutoId().key
var downloadURLSting=String()
photoRef.child(“\(imageName)”).putData(data!,metadata:nil){(metadata,error)in
如果let error=error{
打印(“出现错误”)
打印(错误。本地化描述)
返回
}否则{
//存储下载URL
storage.reference().downloadURL(完成:{(url,错误)在
如果错误!=nil{
打印(错误!.localizedDescription)
返回
}
让downloadURL=url?.absoluteString
让值:Dictionary=[“uid”:uid,“caption”:caption??”,“downloadURL”,“timestamp”:ServerValue.timestamp(),“businessName”:loggedInUserData?[“businessName”]as!字符串,“businessStreet”:loggedInUserData?[“businessCity”]as!字符串,“businessState”:loggedInUserData?[“businessState”]as!String,“businessZIP”:loggedInUserData?[“businessZIP”]as!String,“businessPhone”:loggedInUserData?[“businessPhone”]as!String,“businessWebsite”:loggedInUserData?[“businessLatitude”]as!String,“Business经度”:loggedInUserData[“BusinessLength”]as!String,“facebookURL”:loggedInUserData?[“facebookURL”]as!String,“twitterURL”:loggedInUserData?[“twitterURL”]as!String,“instagramURL”:loggedInUserData?[“googleURL”]as!String,“Yelpur”:loggedInUserData?[“Yelpur”]as!String,“foursquareURL”:loggedInUserData?[“Yelpur”]as!String,“foursquareURL”:loggedInUserData?[“foursquareURL”]as!字符串,“snapchatURL”:loggedInUserData?[“snapchatURL”]as!字符串,“imageID”:imageName,“postID”:postID]
//在数据库中存储下载URL
让databaseRef=Database.Database().reference()
让path=databaseRef.child(“posts”).child((loggedInUser?.uid)!).childByAutoId()
setValue(值){(错误,ref)->中的Void
如果错误!=nil{
打印(“在数据库中保存帖子时出错”)
}否则{
//重置标题字段
self.descriptionTextView.text=“”
//重置占位符图像
self.imageView.image=UIImage(名为:“filterPlaceholder”)
MBProgressHUD.hide(用于:self.view,动画:true)
让viewConrolller=self.storyboard?.instanceeviewcontroller(带有标识符:“业务概要”)作为!UITabBarController
self.present(viewConrolller,动画:true,完成:nil)
}
}
})
}
}
只要下载URL字符串为零就可以了

 let photosRef = storage.reference().child("posts").child((loggedInUser?.uid)!)
    let usersRef = Database.database().reference().child("Businesses")
    let databaseRef = Database.database().reference()
    let imageName = NSUUID().uuidString
    let photoRef = photosRef.child("\(uid)")
    let postID = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId().key
    photoRef.child("\(imageName)").putData(data!, metadata: nil) { (metaData,error) in
        if let error = error {
            print("there was an error")
            print(error.localizedDescription)
            return
        } else {
            // store downloadURL
            photoRef.downloadURL(completion: {(url, error) in
                if error != nil {

                    guard let downloadURL = url?.absoluteString else { return }

                    let values: Dictionary<String, Any> = ["uid": uid, "caption": caption ?? "", "download_url": downloadURL, "timestamp": ServerValue.timestamp(), "businessName":loggedInUserData?["businessName"] as! String, "businessStreet":loggedInUserData?["businessStreet"] as! String, "businessCity":loggedInUserData?["businessCity"] as! String, "businessState":loggedInUserData?["businessState"] as! String, "businessZIP":loggedInUserData?["businessZIP"] as! String, "businessPhone":loggedInUserData?["businessPhone"] as! String, "businessWebsite":loggedInUserData?["businessWebsite"] as! String, "businessLatitude":loggedInUserData?["businessLatitude"] as! String, "businessLongitude":loggedInUserData?["businessLongitude"] as! String, "facebookURL":loggedInUserData?["facebookURL"] as! String, "twitterURL":loggedInUserData?["twitterURL"] as! String, "instagramURL":loggedInUserData?["instagramURL"] as! String, "googleURL":loggedInUserData?["googleURL"] as! String, "yelpURL":loggedInUserData?["yelpURL"] as! String, "foursquareURL":loggedInUserData?["foursquareURL"] as! String, "snapchatURL":loggedInUserData?["snapchatURL"] as! String, "imageID": imageName, "postID": postID]

                    // store downloadURL at database
                    let databaseRef = Database.database().reference()
                    let path = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId()
                    path.setValue(values) { (error, ref) -> Void in
                        if error != nil {
                            print("error saving post in db")
                        } else {
                            // reset caption field
                            self.descriptionTextView.text = ""
                            // reset placeholder image
                            self.imageView.image = UIImage(named: "filterPlaceholder")
                            MBProgressHUD.hide(for: self.view, animated: true)
                            let viewConrolller = self.storyboard?.instantiateViewController(withIdentifier: "Business Profile") as! UITabBarController
                            self.present(viewConrolller, animated: true, completion: nil)
                        }
                    }
                } else {
                    print(error!.localizedDescription)
                    print("error")
                    return
                }
            })
        }
    }
let photoref=storage.reference().child(“posts”).child((loggedInUser?.uid)!)
让usersRef=Database.Database().reference().child(“业务”)
让databaseRef=Database.Database().reference()
让imageName=nsuid().uuidString
让photoRef=photoRef.child(“\(uid)”)
让postID=databaseRef.child(“posts”).child((loggedInUser?.uid)!).childByAutoId().key
photoRef.child(“\(imageName)”).putData(data!,metadata:nil){(metadata,error)in
如果let error=error{
打印(“出现错误”)
打印(错误。本地化描述)
返回
}否则{
//存储下载URL
photoRef.downloadURL(完成:{(url,错误)在
如果错误!=nil{
guard let downloadURL=url?.absoluteString else{return}
让值:Dictionary=[“uid”:uid,“caption”:caption??”,“downloadURL”,“timestamp”:ServerValue.timestamp(),“businessName”:loggedInUserData?[“businessName”]as!字符串,“businessStreet”:loggedInUserData?[“businessCity”]as!字符串,“businessState”“:loggedInUserData?[“businessState”]as!String,“businessZIP”:loggedInUserData?[“businessZIP”]as!String,“businessPhone”:loggedInUserData?[“businessPhone”]as!String,“businessWebsite”:loggedInUserData?[“businessLatitude”]as!String,“businessLatitude”:loggedInUserData?[“businessLatitude”]as!String,“Business经度”:loggedInUserData[“BusinessLength”]as!String,“facebookURL”:loggedInUserData?[“facebookURL”]as!String,“twitterURL”:loggedInUserData?[“twitterURL”]as!String,“instagramURL”:loggedInUserData?[“googleURL”]as!String,“Yelpur”:loggedInUserData?[“Yelpur”]as!String,“foursquareURL”:loggedInUserData?[“Yelpur”]as!String,“foursquareURL”:loggedInUserData?[“foursquareURL”]as!字符串,“snapchatURL”:loggedInUserData?[“snapchatURL”]as!字符串,“imageID”:imageName,“postID”:postID]
//在数据库中存储下载URL
让databaseRef=Database.Database().reference()
让path=databaseRef.child(“posts”).child((logge
 let photosRef = storage.reference().child("posts").child((loggedInUser?.uid)!)
    let usersRef = Database.database().reference().child("Businesses")
    let databaseRef = Database.database().reference()
    let imageName = NSUUID().uuidString
    let photoRef = photosRef.child("\(uid)")
    let postID = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId().key
    photoRef.child("\(imageName)").putData(data!, metadata: nil) { (metaData,error) in
        if let error = error {
            print("there was an error")
            print(error.localizedDescription)
            return
        } else {
            // store downloadURL
            photoRef.downloadURL(completion: {(url, error) in
                if error != nil {

                    guard let downloadURL = url?.absoluteString else { return }

                    let values: Dictionary<String, Any> = ["uid": uid, "caption": caption ?? "", "download_url": downloadURL, "timestamp": ServerValue.timestamp(), "businessName":loggedInUserData?["businessName"] as! String, "businessStreet":loggedInUserData?["businessStreet"] as! String, "businessCity":loggedInUserData?["businessCity"] as! String, "businessState":loggedInUserData?["businessState"] as! String, "businessZIP":loggedInUserData?["businessZIP"] as! String, "businessPhone":loggedInUserData?["businessPhone"] as! String, "businessWebsite":loggedInUserData?["businessWebsite"] as! String, "businessLatitude":loggedInUserData?["businessLatitude"] as! String, "businessLongitude":loggedInUserData?["businessLongitude"] as! String, "facebookURL":loggedInUserData?["facebookURL"] as! String, "twitterURL":loggedInUserData?["twitterURL"] as! String, "instagramURL":loggedInUserData?["instagramURL"] as! String, "googleURL":loggedInUserData?["googleURL"] as! String, "yelpURL":loggedInUserData?["yelpURL"] as! String, "foursquareURL":loggedInUserData?["foursquareURL"] as! String, "snapchatURL":loggedInUserData?["snapchatURL"] as! String, "imageID": imageName, "postID": postID]

                    // store downloadURL at database
                    let databaseRef = Database.database().reference()
                    let path = databaseRef.child("posts").child((loggedInUser?.uid)!).childByAutoId()
                    path.setValue(values) { (error, ref) -> Void in
                        if error != nil {
                            print("error saving post in db")
                        } else {
                            // reset caption field
                            self.descriptionTextView.text = ""
                            // reset placeholder image
                            self.imageView.image = UIImage(named: "filterPlaceholder")
                            MBProgressHUD.hide(for: self.view, animated: true)
                            let viewConrolller = self.storyboard?.instantiateViewController(withIdentifier: "Business Profile") as! UITabBarController
                            self.present(viewConrolller, animated: true, completion: nil)
                        }
                    }
                } else {
                    print(error!.localizedDescription)
                    print("error")
                    return
                }
            })
        }
    }
storageRef.downloadURL(completion: {(url, error) in
    if error != nil {
     print(error!.localizedDescription)
       return
    }
    let downloadURL = url?.absoluteString
    let values: Dictionary<String, Any> = ["download_url": downloadURL]
})
storageRef.downloadURL(completion: {(url, error) in
    if error != nil {
     print(error!.localizedDescription)
       return
    }
    let downloadURL = url?.absoluteString
    let values: Dictionary<String, Any> = ["download_url": downloadURL]

    let databaseRef = Database.database().reference()
    let path = databaseRef.child("posts").child((self.loggedInUser?.uid)!).childByAutoId()
    path.setValue(values) { (error, ref) -> Void in
        ...