简体   繁体   中英

Google Amplify iOS App -> NSUnknownKeyException

I am trying to use the google federated sign-in feature provided by Cognito in an iOS App using AWSMobileClient. I have the latest amplify (4.11.0) and AWS toolkit.

I have the following in my pod file:

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

I use the standard AWSMobileClient initialize call and then showSignIn method to bring the login screen, but I get the following exception:

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

My awsconfiguration file has the following entry:

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

which was generated by amplify when I created the auth backend (along with other entries for the user pool, identity etc). I have also setup the necessary project and credentials on the google developer website.

Using the Cognito hosted UI (browser URL), I can login with google with no issue, just not using the iOS app.

If I remove the ClientId-iOS entry, the exception does not occur anymore, but the login screen does not have a google button.

Not quite an answer, but there is too much here for a comment.

Your crash appears to be occurring in the file found here :

The relevant code:

- (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;
}

I marked the line where your crash appears to occur.

It is attempting to set the property seen here in GIDSignIn

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

This is just a cursory glance, but the sharedInatance getting called is created on a background thread, so the possibility exists that a race issue is causing the problem. I'd suggest some breakpoints in this area and test to see what threads you are on and what properties are available at the time of the call.

Assuming something is wrong with the SDK, you can create an issue and they may fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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