我已经有一个可以完全使用 SwiftUI 构建的应用程序。我使用 Firebase 使用 Cloud Functions 进行身份验证和通知。
现在使用新的 SwiftUI App->Scene->View 构造,我无法将设置添加到我的应用程序中。
例如- >初期FirebaseApp.configure()将首先进去didFinishLaunchingWithOptions的AppDelegate,现在我在哪里添加此配置的损失。
设置远程通知也是如此。
PS:如果需要前一个应用程序的更多详细信息/代码,请发表评论。我没有添加任何代码,因为我觉得没有必要。
firebase firebase-authentication swiftui swiftui-environment
我正在尝试在我的应用中记录屏幕名称,但我在 Firebase Analytics 中没有设置 95%。
为了onAppear我的观点Analytics.setScreenName("screenName", screenClass: "screenName")
我应该以不同的方式这样做吗?看起来 Analytics for iOS 可以与UIViewControllers结合使用,但由于这是一个 SwiftUI 应用程序,并且没有关于如何使用它的文档。
我一直在关注https://firebase.google.com/docs/auth/ios/apple并且它确实提到了我收到的错误“将 SHA256 哈希随机数作为十六进制字符串发送”,但它没有提供任何帮助解决它,我的搜索没有给我一个有效的解决方案。
我的视图控制器代码摘录是
fileprivate var currentNonce: String?
@objc @available(iOS 13, *)
func startSignInWithAppleFlow() {
let nonce = randomNonceString()
currentNonce = nonce
let appleIDProvider = ASAuthorizationAppleIDProvider()
let request = appleIDProvider.createRequest()
request.requestedScopes = [.fullName, .email]
request.nonce = sha256(nonce)
print(request.nonce)
let authorizationController = ASAuthorizationController(authorizationRequests: [request])
authorizationController.delegate = self
authorizationController.presentationContextProvider = self
authorizationController.performRequests()
}
@available(iOS 13, *)
private func sha256(_ input: String) -> String {
let inputData = Data(input.utf8)
let hashedData = SHA256.hash(data: inputData)
let hashString = hashedData.compactMap {
return String(format: …Run Code Online (Sandbox Code Playgroud) 我想对用户进行身份验证,并使用用户名(第一个和最后一个)使用 Firestore 创建用户数据库。我可以创建用户,但无法同时创建数据库。
\n\n这是我的 SessionStore,用于注册和登录。通过注册,我想获取用户名并创建一个数据库。(下面没有代码,因为没有任何效果)
\n\n我是初学者,所以我希望得到详细的答案。
\n\n多谢!
\n\nimport Firebase\nimport Combine\n\nclass SessionStore: ObservableObject {\n var didChange = PassthroughSubject<SessionStore, Never>()\n @Published var session: User? {didSet {self.didChange.send(self) }}\n var handle: AuthStateDidChangeListenerHandle?\n\n func listen() {\n handle = Auth.auth().addStateDidChangeListener({ (auth, user) in\n if let user = user {\n self.session = User(uid: user.uid, email: user.email)\n } else {\n self.session = nil\n }\n })\n }\n\n func signUp(email: String, password: String, handler: @escaping AuthDataResultCallback) {\n Auth.auth().createUser(withEmail: email, password: password, completion: handler)\n }\n\n func signIn(email: …Run Code Online (Sandbox Code Playgroud) firebase firebase-authentication google-cloud-firestore swiftui
@Published var isNewUser: Bool?
init() {
self.isNewUser = false
}
func checkIfTheUserExistsInDataBase(
userID: String?, completion: @escaping (_ isNewuser: Bool) -> Void
) {
let docRef = db.collection("users").whereField("user_id", isEqualTo: userID!).limit(to: 1)
docRef.getDocuments { querySnapshot, error in
if error != nil {
print(error?.localizedDescription)
} else {
if let doc = querySnapshot?.documents, doc.isEmpty {
completion(true)
} else {
completion(false)
}
}
}
}
func login(
email: String, password: String,
completion: @escaping (_ error: Error?, _ isEmailVerified: Bool) -> Void
) {
Auth.auth().signIn(withEmail: email, …Run Code Online (Sandbox Code Playgroud) 我使用列表来显示用户通过表单输入的伤害数据,该数据已成功添加到 Cloud Firestore。我现在想添加一个删除功能,删除列表中选定的伤害。
这是我的Injury结构:
import SwiftUI
import FirebaseFirestoreSwift
struct Injury: Identifiable, Codable {
@DocumentID var id: String? = UUID().uuidString
var userId: String?
var specificLocation: String
var comment: String
var active: Bool
var injuryDate: Date
var exercises: String
var activity: String
var location: String
}
Run Code Online (Sandbox Code Playgroud)
我的InjuriesViewModel:
import SwiftUI
import Firebase
import FirebaseFirestore
import FirebaseFirestoreSwift
class InjuriesViewModel: ObservableObject {
@Published var injuries = [Injury]()
private var db = Firestore.firestore()
func fetchData () {
let userId = Auth.auth().currentUser?.uid
db.collection("injuries") …Run Code Online (Sandbox Code Playgroud)