【问题标题】:Google Amplify iOS App -> NSUnknownKeyExceptionGoogle Amplify iOS App -> NSUnknownKeyException
【发布时间】:2020-04-22 08:08:45
【问题描述】:

我正在尝试在使用 AWSMobileClient 的 iOS 应用程序中使用 Cognito 提供的谷歌联合登录功能。我有最新的放大 (4.11.0) 和 AWS 工具包。

我的 pod 文件中有以下内容:

pod 'AWSAPIGateway'
pod 'AWSMobileClient'
pod 'AWSAuthUI'
pod 'AWSUserPoolsSignIn'
pod 'GoogleSignIn'
pod 'AWSGoogleSignIn'

我使用标准的AWSMobileClient 初始化调用然后showSignIn 方法带来登录屏幕,但我得到以下异常:

'NSUnknownKeyException', reason: '[<GIDSignIn 0x600003f19e00> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key uiDelegate.'

我的awsconfiguration 文件有以下条目:

"GoogleSignIn": {
          "Permissions": "email,profile,openid",
          "ClientId-WebApp": "XXXXXXXXX-YYYYYYYYYYYYYY.apps.googleusercontent.com",
          "ClientId-iOS": "ZZZZZZZZZZZ-VVVVVVVVVVVVV.apps.googleusercontent.com"
      }

它是在我创建身份验证后端时由 amplify 生成的(以及用户池、身份等的其他条目)。我还在谷歌开发者网站上设置了必要的项目和凭据。

使用 Cognito 托管的 UI(浏览器 URL),我可以毫无问题地使用 google 登录,只是不使用 iOS 应用程序。

如果我删除 ClientId-iOS 条目,异常不会再发生,但登录屏幕没有 google 按钮。

【问题讨论】:

    标签: ios amazon-cognito aws-amplify nsunknownkeyexception


    【解决方案1】:

    不是一个完整的答案,但这里的评论太多了。

    您的崩溃似乎发生在file found here

    相关代码:

    - (instancetype)initWithGoogleClientID:(NSString *)googleClientID {
        if (self = [super init]) {
            _semaphore = dispatch_semaphore_create(0);
            
            NSOperationQueue *operationQueue = [NSOperationQueue new];
            _executor = [AWSExecutor executorWithOperationQueue:operationQueue];
            
            _signInViewController = nil;
            
            _signInClient = [NSClassFromString(@"GIDSignIn") sharedInstance];
            [self.signInClient setValue:self forKey:@"delegate"];
            [self.signInClient setValue:self forKey:@"uiDelegate"]; // Crashes here
            [self.signInClient setValue:googleClientID forKey:@"clientID"];
            [self.signInClient setValue:@[AWSGoogleSignInProviderClientScope, AWSGoogleSignInProviderOIDCScope] forKey:@"scopes"];
        }
        
        return self;
    }
    

    我标记了您的崩溃似乎发生的行。

    它正在尝试设置GIDSignIn中看到的属性

    // The object to be notified when sign in dispatch selection is finished.
    @property(nonatomic, weak) id<GIDSignInUIDelegate> uiDelegate;
    

    这只是粗略的一瞥,但被调用的sharedInatance 是在后台线程上创建的,因此存在竞争问题导致问题的可能性。我建议在该区域设置一些断点并进行测试,以查看您在哪些线程以及调用时可用的属性。

    假设 SDK 有问题,您可以创建一个问题,他们可能会修复它。

    【讨论】:

    • 感谢 CodeBender 对此进行调查。似乎 AWSGoogleSignIn pod 包含旧版本的 google GDSignIn 类,它曾经有一个 uiDelegate 属性。从 GoogleSignIn 的 5.0 版本开始,此属性已被消除,根据 github.com/CocoaPods/Specs/tree/master/Specs/d/4/0/GoogleSignIn 更新 Podfile 以限制 GoogleSignIn 的版本修复了该问题。 pod 'GoogleSignIn','~> 4.4.0'
    猜你喜欢
    • 2015-08-25
    • 2021-01-22
    • 2015-12-04
    • 1970-01-01
    • 2021-08-24
    • 2022-12-27
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多