我正在努力实现与苹果的签到王国. 我已经完成了文档中的配置:https://www.mongodb.com/docs/atlas/app-services/authentication/apple/#std-label-apple-id-authentication

现在我正在try 添加苹果按钮和流程的登录.

SwiftUI上的登录按钮:

SignInWithAppleButton(.signIn, onRequest: { request in
    isLoggingIn = true
    request.requestedScopes = [.email]
}, onCompletion: { result in
    switch result {
    case .success(let authResults):
        guard let credentials = authResults.credential as? ASAuthorizationAppleIDCredential,
              let identityToken = credentials.identityToken,
              let identityTokenString = String(data: identityToken, encoding: .utf8) else { return }
        
        repo.loginwithApple(appleTokenIDString: identityTokenString) { user, error in
            
        }
    case .failure(let error):
        isLoggingIn = false
    }
})

repo.loginwithApple从共享Kotlin存储库中调用该方法:

suspend fun loginwithApple(appleTokenIDString: String): User {
    var credentials = Credentials.apple(idToken = appleTokenIDString)

    return appService.login(credentials = credentials)
}

每当我try 使用Apple登录按钮进行登录时,我都会得到这样的异常:

libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SharedRealmRepo loginwithAppleAppleTokenIDString:completionHandler:]: unrecognized selector sent to instance 0x281fe4960'
terminating with uncaught exception of type NSException

你知道为什么会发生这种例外情况吗?

推荐答案

从XCode中删除输出文件似乎可以解决这个问题,但我不知道为什么.

enter image description here

也许有人能解释为什么会发生这种情况.输出文件不会让领域重新生成吗?

Swift相关问答推荐

使用简单变量和函数的奇怪行为

MyApp类型不符合协议App''''

如何防止自动状态恢复,如果应用程序被启动打开特定的文档?

如何分解阿拉伯字母?

如何使泡泡上的箭头直达封闭矩形

SwiftData:非法try 在不同上下文中的对象之间建立关系

将变量设置为 @Published 会 destruct 代码而不会出现任何错误

在PrimitiveSequence上引用实例方法xxx需要类型A和any B等效

URL appendPathComponent(_:) 已弃用?

为什么在Swift中每次调用Decimal类型的formatted()方法都会越来越慢?

如何在 ZStack 中单独下移卡片?

在 Select 器上显示alert Select SwiftUI

将数据附加到 Firebase 实时数据库后,NavigationLink 将我重定向到上一个视图

如何让 UIKit 挤压你的视图,使其适合屏幕

如何自己快速编写 Hashable 协议

在运行时访问 UIView 宽度

Swift 3:日期与 NSDate?

自动布局:获取 UIImageView 高度以正确计算单元格高度

不能从非开放类继承 swift

使用 swift IOS 使 UIBarButtonItem 消失