有没有办法让URL请求链接特定于用户?我正在尝试与用户特定的Firebase存储文件建立某些链接。我是否必须更改xcode或Firebase存储规则中的代码?
func yhandleDownload() {
print(123)
let webView = UIWebView (frame: view.frame)
webView.backgroundColor = UIColor.black
view.addSubview(webView)
webView.loadRequest(URLRequest(url: URL(string: "https://firebasestorage.googleapis.com")!))
webView.scalesPageToFit = true
这就是我现在设置代码的方式,它允许登录到应用程序的所有用户打开链接。
答案 0 :(得分:0)
您应该使用内置的下载方法(例如,我们将使用FirebaseUI直接将图像下载到UIImageView
):
// Get the current user's UID
let currentUser = FIRAuth.auth().currentUser?.uid
// Reference to a user's image file in Firebase Storage
let reference = storageRef.child("users/\(currentUser)/image.png")
// UIImageView in your ViewController
let imageView: UIImageView = self.imageView
// Placeholder image
let placeholderImage = UIImage(named: "placeholder.jpg")
// Load the image using SDWebImage
imageView.sd_setImage(with: reference, placeholderImage: placeholderImage)
除了适当设置安全规则外:
service firebase.storage {
match /b/{bucket}/o {
match /users/{userId}/{allUserFiles=**} {
allow read, write: if request.auth.uid == userId;
}
}
}