带有 FirebaseFirestore 的 SwiftUI

问题描述 投票:0回答:1

我用谷歌搜索了很多,但还没有找到答案。我是一名初学者,刚刚开始使用 Xcode 进行 SwiftUI 编程。这是一个非常简单的例子。我使用 Xcode 15.4、Firebase 11.1.0、ISO 17.5 模拟器和 iPhone 15 Pro Max 进行了测试。请注意,从数据库获取数据正在工作。

警告:调用absl::InitializeLog()之前的所有日志消息都会写入STDERR I0000 00:00:1724935720.773638 111338 config.cc:230] gRPC实验已启用:call_status_override_on_cancellation、http2_stats_fix、monitoring_experiment、pick_first_new、trace_record_callops、 work_serializer_clears_time_cache nw_connection_get_connected_socket_block_invoke [C1 ] 客户端在未连接的 nw_connection TCP Conn 0x6000033050e0 上调用 nw_connection_get_connected_socket 失败:错误 0:50 [50] I0000 00:00:1724935720.853425 111359 subchannel.cc:806] 子通道 0x104919e10 v6:%5B2404:6800:4006:814::200a %5D:443,args = {grpc.client_channel_factory = 0x600000049cc0,grpc.default_authority = firestore.googleapis.com,grpc.http2_scheme = https,grpc.internal.channel_credentials = 0x60000260d020,grpc.internal.client_channel_call_destination = 0x102cd4fb8,gr电脑内部。 event_engine=0x600000008ef0、grpc.internal.security_connector=0x600002c01400、grpc.internal.subchannel_pool=0x6000029442a0、grpc.keepalive_time_ms=30000、grpc.primary_user_agent=grpc-c++/1.65.1、grpc.resource_quota=0x6 00000cbfe40,grpc.server_uri=dns: ///firestore.googleapis.com}}:连接失败(未知:(域:NSPOSIXErrorDomain,代码:50,说明:操作无法完成。网络已关闭){文件:“/var/folders/hn/5bx1f4_d4ds5vhwhkxc7vdcr0000gn/T/ZipRelease/2024-07-25T04-01-28/project-ios/Pods/gRPC-Core/src/core/lib/transport/error_utils .cc", file_line:150,created_time:"2024-08-30T00:48:40.853037+12:00", grpc_status:2}),后退 955 毫秒

错误代码

我不明白为什么会出现此错误。请帮忙。

以下部分是源代码。

import SwiftUI
import Firebase

@main
struct BizKoreaNZApp: App {
    init() {
        FirebaseApp.configure()
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}

import SwiftUI
import FirebaseFirestore

struct ContentView: View {
    @State private var users = [User]()
    @State private var isLoading = false
    
    var body: some View {
        Text("Start")
        NavigationView {
            List(users) { user in
                Text(user.name)
            }
            .navigationTitle("Users")
            .onAppear {
                fetchUsers()
            }
            .overlay(isLoading ? ProgressView() : nil)
        }
    }
    func fetchUsers() {
        isLoading = true
        let db = Firestore.firestore()
        db.collection("users").getDocuments { snapshot, error in
            isLoading = false
            if let error = error {
                print("Error fetching users: \(error.localizedDescription)")
            } else if let snapshot = snapshot {
                self.users = snapshot.documents.map { document in
                    let data = document.data()
                    let name = data["name"] as? String ?? ""
                    return User(name: name)
                }
            }
        }
    }
}
struct User: Identifiable {
    let id = UUID()
    var name: String
}
ios firebase google-cloud-firestore swiftui
1个回答
0
投票

我现在也遇到同样的错误,有什么帮助吗?

© www.soinside.com 2019 - 2024. All rights reserved.