简体   繁体   English

在 Xcode 14 - iOS 16 上的 swift/swiftui 中使用 Firestone 获取数据时出现问题

[英]Problem fetching data with Firestone in swift/swiftui on Xcode 14 - iOS 16

I have a problem to fetch data on iOS 16 in Swift/Swiftui with Firebase.我在使用 Firebase 的 Swift/Swiftui 中获取 iOS 16 上的数据时遇到问题。 When I clicked on the button to open the view the data doesn't appear until I HAVE to slide down and reopen the view.当我单击按钮打开视图时,数据不会出现,直到我必须向下滑动并重新打开视图。 It's working very well on iOS 15 but not on iOS 16. Thank you for you help.它在 iOS 15 上运行良好,但在 iOS 16 上运行良好。感谢您的帮助。 I also recorded a video to explain the problem.我还录制了一个视频来解释这个问题。 And here is my code:这是我的代码:

Function to fetch the data: Function 获取数据:

func QueryOrder() {
    var query: Query!
    let uid = Auth.auth().currentUser!.uid
    query = dataBase.collection("Users").whereField("uid", isEqualTo: uid)
    query.addSnapshotListener { (QuerySnapshot, error) in
        guard let documents = QuerySnapshot?.documents else {
            print("no document")
            return
        }
            self.orders = documents.map { (QueryDocumentSnapshot) -> Order_placed in
                let data = QueryDocumentSnapshot.data()
                let customer_name = data["customer_name"] as? String ?? ""
                let total = data["total"] as? Double ?? 0
                let order_id = data["order_id"] as? String ?? ""
                let code_for_delivery = data["code_for_delivery"] as? String ?? ""
                let customer_address = data["customer_address"] as? String ?? ""
                let customer_unit_type = data["customer_unit_type"] as? String ?? ""
                let customer_phone_number = data["customer_phone_number"] as? Int ?? 0
                let store_name = data["store_name"] as? String ?? ""
                let order_status = data["order_status"] as? String ?? ""
                return Order_placed(customer_name: customer_name, total: total, store_name: store_name, customer_address: customer_address, customer_phone_number: customer_phone_number, customer_unit_type: customer_unit_type, code_for_delivery: code_for_delivery, order_id: order_id, status: order_status)
        }
    }
}

Here is my view:这是我的看法:

ScrollView {
        
        
        LazyVGrid(columns: items, spacing: 10) {
            ForEach(StoreFirebase.orders) { item in
            
                currentOrdersViewModel(item: item, showCard: $showCard, orderID: $orderID)
            
            }
        }
        .navigationBarItems(trailing:
            Button (action: {
            self.presentationMode.wrappedValue.dismiss()
        }){
            ZStack {
                Circle()
                    .fill(Color(white: colorScheme == .dark ? 0.19 : 0.93))
                Image(systemName: "xmark")
                    .resizable()
                    .scaledToFit()
                    .font(Font.body.weight(.bold))
                    .scaleEffect(0.416)
                    .foregroundColor(Color(white: colorScheme == .dark ? 0.62 : 0.51))
                    }
        }.frame(width: 40, height: 40)
            
        )
        
        
    }
    .onAppear() {
        self.StoreFirebase.QueryOrder()
    
    }

And this is a part of the view Model:这是视图 Model 的一部分:

@ObservedObject private var StoreFirebase = FirebaseViewModel()
var item: Order_placed
@State var ismodal = false
@State var color = ""
@Binding var showCard: Bool
@Binding var orderID: String

var body: some View {
    
    let doubleStr = String(format: "%.2f", item.total)
    
    ZStack {
        Rectangle()
            .foregroundColor(Color(red: 248 / 255, green: 248 / 255, blue: 255 / 255))
            .cornerRadius(10)
            .frame(minHeight: 50)  // ,maxHeight: 240)
        
        if item.status == "Canceled" {
            Text("Status: \(item.status)")
                .foregroundColor(Color.white)
                .font(Font.system(.footnote, design: .default).weight(.semibold))
                .padding(5)
                .padding(.horizontal, 2)
                .background(RoundedRectangle(cornerRadius: 14, style: .continuous)
                    .foregroundColor(Color.red.opacity(0.80))
                    .opacity(1), alignment: .center)
                .position(x: 200, y: 0)
                Spacer(minLength: 0)
        } else {
        Text("Status: \(item.status)")
            .foregroundColor(Color.white)
            .font(Font.system(.footnote, design: .default).weight(.semibold))
            .padding(5)
            .padding(.horizontal, 2)
            .background(RoundedRectangle(cornerRadius: 14, style: .continuous)
                .foregroundColor(Color.blue.opacity(0.80))
                .opacity(0.55), alignment: .center)
            .position(x: 200, y: 0)
            Spacer(minLength: 0)
        }
        
        
        
    VStack (spacing: 10) {
            
            HStack {
            Text("Order ID :")
                    .font(.system(size: 15, weight: .heavy))
                 Spacer(minLength: 0)
                Text(item.order_id)
                    .font(.system(size: 15, design: .monospaced))
            }.padding()
            
            HStack {
                Text("Code to give to your courier :")
                        .font(.system(size: 15, weight: .heavy))
                     Spacer(minLength: 0)
                if item.status != "Courier is arrive" {
                    Text(item.code_for_delivery)
                        .font(.system(size: 15, design: .monospaced))
                        .blur(radius: 5)
                } else {
                    Text(item.code_for_delivery)
                        .font(.system(size: 15, design: .monospaced))
                }
            }.padding()
        
            HStack {
                Text("Need help with this order?")
                    .font(.system(size: 15, weight: .heavy))
                    Spacer(minLength: 0)
                Button(action: {
                  //  sendMessage()
                    self.orderID = item.order_id
                    self.showCard = true
                })
                {
                        Text("Contact support")
                        .font(.system(size: 16, weight: .semibold))
                        .foregroundColor(.red)
                    }

This is the link of the video if you want to see the problem (dropbox link no download requires)如果您想查看问题,这是视频的链接(无需下载的保管箱链接)

Video 视频

Thank you so much for your help, I tried to understand where the problem is from but I still don't know and it's working well on iOS 15.非常感谢您的帮助,我试图了解问题出在哪里,但我仍然不知道它在 iOS 15 上运行良好。

I am facing same issue in iOS 16 devices but it's working fine in iOS 15 and iOS 16 simulators.我在 iOS 16 设备中面临同样的问题,但它在 iOS 15 和 iOS 16 模拟器中运行良好。

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

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