我试图按照此处的说明操作:https://firebase.google.com/docs/auth/ios/email-link-auth
...和这里(对于动态链接部分):https://firebase.google.com/docs/dynamic-links/ios/receive
...让我的iOS应用程序告诉Firebase发送带有链接的电子邮件,当用户在其设备上打开时,会导致我的应用程序拥有经过身份验证的User
对象。
@objc func handleFirebaseDynamicLink(_ link: DynamicLink) {
guard let link = link.url?.absoluteString else {
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, link had no url")
return
}
guard let email = self.emailAddressLastEntered, Auth.auth().isSignIn(withEmailLink: link) else {
WLog("FirebaseProvider handleFirebaseDynamicLink: WARNING, not a signInWithEmailLink or no emailAddress?")
return
}
问题:出于某种原因,Auth.auth().isSignIn...
返回false,即使它给出的链接看起来是正确的:
(lldb) po link
"https://<redacted>.firebaseapp.com/__/auth/action?apiKey=<redacted>&mode=signIn&oobCode=123459g71QBFRozWp4fvi-izDstx9BE2o3zhPc_jZQAAAFiU_tqpg&continueUrl=https://<redacted>/applinks/firebaseprovider/signin"
如果我忽略了这个并且只是调用Auth.auth().signIn(withEmail: email, link: link)
,它会崩溃,但尝试将nil值插入NSDictionary中除外:(
以下是我打电话来生成电子邮件发送的代码:
let actionCodeSettings = ActionCodeSettings.init()
actionCodeSettings.url = URL.init(string: "https://<redacted>/applinks/firebaseprovider/signin")
actionCodeSettings.handleCodeInApp = true
actionCodeSettings.setIOSBundleID(Bundle.main.bundleIdentifier!)
Auth.auth().sendSignInLink(toEmail: emailAddress, actionCodeSettings: actionCodeSettings, completion: { (error) in
if let error = error {
WLog("FirebaseProvider signIn: ERROR on sendSignInLink: \(error.localizedDescription)")
waitingForUserBlock(false)
return
}
self.emailAddressLastEntered = emailAddress
self.signedInBlock = signedInBlock
waitingForUserBlock(true)
})
...这里是获取处理程序的AppDelegate代码:
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
DDLogInfo(@"AppDelegate continueUserActivity: %@", userActivity.debugDescription);
BOOL handled = [[FIRDynamicLinks dynamicLinks] handleUniversalLink:userActivity.webpageURL completion:^(FIRDynamicLink * _Nullable dynamicLink, NSError * _Nullable error) {
if (error) {
DDLogWarn(@"AppDelegate continueUserActivity: ERROR on handleUniversalLink: %@", error.debugDescription);
return;
}
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
}];
return handled;
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options {
FIRDynamicLink *dynamicLink = [[FIRDynamicLinks dynamicLinks] dynamicLinkFromCustomSchemeURL:url];
if (dynamicLink) {
[FirebaseProvider.shared handleFirebaseDynamicLink:dynamicLink];
return YES;
} else {
DDLogWarn(@"%s, WARNING: openURL returning FALSE because i didn't know the prefix: %@", __PRETTY_FUNCTION__, url.absoluteString);
}
return false;
}
我还确保重新下载GoogleService-Info.plist
文件,我在那里看到IS_SIGNIN_ENABLED
是YES
,因为我期待。
非常感谢。
答案 0 :(得分:1)
原来问题是一个人不应该自己处理dynamicLink。 IE浏览器。不要致电isSignIn
只需将整个链接(动态或其他)直接传递到git remote -v