简体   繁体   English

我收到 firebase 权限错误。 即使我按照 firebase 规则做了,它也不起作用

[英]I am getting firebase permission error. Even though I did it according to the firebase rules, it doesn't work

Hi firebase I wanted to upload pdf doc style data from icloud by connecting to simulator.嗨 firebase 我想通过连接到模拟器从 icloud 上传 pdf 文档样式数据。 but I am getting a user access error.但我收到用户访问错误。 I don't want to have a user already in my application.我不想在我的应用程序中已有用户。 What I did as in the firebase documentation is still not working.我在 firebase 文档中所做的仍然无法正常工作。 also allow read, write: if true;也允许读、写:如果为真; I haven't tried it still does not allow access我没试过它仍然不允许访问

Firebase; Firebase;

  rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write;
    }
  }
}

SwiftUI contentview; SwiftUI 内容查看;



import SwiftUI
import MobileCoreServices
import Firebase
struct ContentView: View {
    
    @State var show = false
    @State var alert = false
    var body: some View {
       
        
        Button {
            
            self.show.toggle()
        } label: {
            Text("Document Picker")
        }
        .sheet(isPresented: $show)
        {
            DocumentPicker(alert: self.$alert)
        }
        .alert(isPresented: $alert) {
            
            Alert(title: Text("Opps Wonderful"), message: Text("OKey Upload"), dismissButton: .default(Text("OK")))
        }   }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}


struct DocumentPicker : UIViewControllerRepresentable {
    func makeCoordinator() -> Coordinator {
        return DocumentPicker.Coordinator(parent1: self)
    }
    
    @Binding var alert: Bool
    
    func makeUIViewController(context: UIViewControllerRepresentableContext <DocumentPicker> ) -> UIDocumentPickerViewController {
        
        
        let picker = UIDocumentPickerViewController(documentTypes:            [String(kUTTypeItem)]  , in: .open)
        picker.allowsMultipleSelection = false
        picker.delegate = context.coordinator
        return picker
}
    
    func updateUIViewController(_ uiViewController: UIDocumentPickerViewController, context: UIViewControllerRepresentableContext<DocumentPicker>) {
        
    }
    
    class Coordinator: NSObject, UIDocumentPickerDelegate {
      
        var parent : DocumentPicker
        
        init (parent1: DocumentPicker)
        {
            parent = parent1
        }
        
        func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentsAt urls: [URL]) {
          
            let bucket = Storage.storage().reference()

            bucket.child((urls.first?.deletingPathExtension().lastPathComponent)!).putFile(from: urls.first!,metadata: nil   ){
                (_, err) in
               
                if err != nil {
                    print ((err?.localizedDescription)!)
                return
            }
        print("succeess")
                self.parent.alert.toggle()
        
        }
    }
}
}

The security rules you're showing are for Cloud Firestore (a document database), while your code is using Cloud Storage (file storage).您显示的安全规则适用于 Cloud Firestore(文档数据库),而您的代码使用 Cloud Storage(文件存储)。 While both are part of Firebase, they each have their own API and their own security rules, and the security rules of one don't apply to the other.虽然两者都是 Firebase 的一部分,但它们都有自己的 API 和自己的安全规则,其中一个的安全规则不适用于另一个。

You'll want to study the documentation on securing Cloud Storage , and then set the security rules for Cloud Storage in your project .您需要研究有关保护 Cloud Storage 的文档,然后在您的项目中设置 Cloud Storage 的安全规则

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM