gpt4 book ai didi

swift - Firebase Twitter oAuth 回调不适用于 Swift ios13

转载 作者:行者123 更新时间:2023-12-04 12:40:42 24 4
gpt4 key购买 nike

我已按照 https://firebase.google.com/docs/auth/ios/twitter-login 上的说明进行操作到 Swift 的 T,我得到 Web 弹出窗口来授权我在 Twitter Dev 上创建的应用程序,回调被调用,然后 Web View 位于 about:blank 的空页面上。除了单击“完成”按钮外,什么也做不了,这会导致错误域=FIRAuthErrorDomain 代码=17058“交互已被用户取消。”回调地址正确。我使用 Twitter Consumer API key 作为进入 Firebase 控制台的 key 。

我错过了什么?

最佳答案

对于仍然无法正常使用回调的每个人,我设法解决了它。遗憾的是,您必须编辑库中的方法(这不是最好的方法,但仍然如此。错误已报告给 firebase 团队)。该方法应该类似于下面的方法(您可以在名为 FIROAuthProvider.m 的文件的第 125 行中找到它。我故意留下注释行,所以您会看到那里的问题...希望它对某人有所帮助:)

- (void)getCredentialWithUIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
completion:(nullable FIRAuthCredentialCallback)completion {
if (![FIRAuthWebUtils isCallbackSchemeRegisteredForCustomURLScheme:self->_callbackScheme]) {
[NSException raise:NSInternalInconsistencyException
format:@"Please register custom URL scheme '%@' in the app's Info.plist file.",
self->_callbackScheme];
}
// __weak __typeof__(self) weakSelf = self;
// __weak FIRAuth *weakAuth = _auth;
// __weak NSString *weakProviderID = _providerID;
dispatch_async(FIRAuthGlobalWorkQueue(), ^{
FIRAuthCredentialCallback callbackOnMainThread =
^(FIRAuthCredential *_Nullable credential, NSError *_Nullable error) {
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion(credential, error);
});
}
};
NSString *eventID = [FIRAuthWebUtils randomStringWithLength:10];
NSString *sessionID = [FIRAuthWebUtils randomStringWithLength:10];
// __strong __typeof__(self) strongSelf = weakSelf;
[self
getHeadFulLiteURLWithEventID:eventID
sessionID:sessionID
completion:^(NSURL *_Nullable headfulLiteURL, NSError *_Nullable error) {
if (error) {
callbackOnMainThread(nil, error);
return;
}
FIRAuthURLCallbackMatcher callbackMatcher =
^BOOL(NSURL *_Nullable callbackURL) {
return [FIRAuthWebUtils
isExpectedCallbackURL:callbackURL
eventID:eventID
authType:kAuthTypeSignInWithRedirect
callbackScheme:self->_callbackScheme];
};
// __strong FIRAuth *strongAuth = weakAuth;
[_auth.authURLPresenter
presentURL:headfulLiteURL
UIDelegate:UIDelegate
callbackMatcher:callbackMatcher
completion:^(NSURL *_Nullable callbackURL,
NSError *_Nullable error) {
if (error) {
callbackOnMainThread(nil, error);
return;
}
NSString *OAuthResponseURLString =
[self OAuthResponseForURL:callbackURL
error:&error];
if (error) {
callbackOnMainThread(nil, error);
return;
}
__strong NSString *strongProviderID = _providerID;
FIROAuthCredential *credential = [[FIROAuthCredential alloc]
initWithProviderID:strongProviderID
sessionID:sessionID
OAuthResponseURLString:OAuthResponseURLString];
callbackOnMainThread(credential, nil);
}];
}];
});
}

关于swift - Firebase Twitter oAuth 回调不适用于 Swift ios13,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59595425/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com