【发布时间】:2021-10-22 11:30:39
【问题描述】:
我将 Google Drive SDK 集成到我的应用中。现在我也想集成 Dropbox,在功能中可能会有更多其他云驱动器。由于现在有两个 URL 方案,我如何确定登录发生时 AppDelegate 方法 func application(_ app: UIApplication, open url: 使用的是哪个 URL 方案?
因为我在 info.plist 中为每个 URL 方案提供了一个标识符。我想也许我可以使用url.scheme.identifer 来区分彼此,但是尝试失败了。他们没有那个链属性。
或者我可以在用户按下登录按钮时手动设置一个标志。那么正确的做法是什么呢?
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
// Google SignIn
return GIDSignIn.sharedInstance.handle(url)
// Dropbox SignIn
return DropboxClientsManager.handleRedirectURL(url) { authResult in
guard let authResult = authResult else { return }
switch authResult {
case .success(let token):
print("Success! User is logged into Dropbox with token: \(token)")
case .cancel:
print("User canceld OAuth flow.")
case .error(let error, let description):
print("Error \(error): \(String(describing: description))")
}
}
}
【问题讨论】:
-
查看 google 文档中的 #2:developers.google.com/identity/sign-in/ios/sign-in,其中显示“// 处理其他自定义 URL 类型。”。我认为这基本上就是您返回 Dropbox 句柄的地方
-
谢谢,这是确定它是否来自谷歌登录的正确方法。但是我仍然需要一种方法来检查 URL 方案来自哪个,因为计划中会有更多的云驱动器,例如 One Drive、Mega。
标签: ios swift url-scheme