ios - 登录 Snapchat 后,SnapKit 无法返回应用
问题描述
在 Snapchat 上进行身份验证后,我一直试图将 Snapchat 引导回我的应用程序,但没有成功。这是我的应用程序委托中的代码,我认为它不起作用:
import UIKit
import SCSDKLoginKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
return SCSDKLoginClient.application(app, open: url, options: options)
}
@available (iOS 13, *)
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let options: [UIApplication.OpenURLOptionsKey : Any] = [
.openInPlace: urlContext.options.openInPlace,
.sourceApplication: urlContext.options.sourceApplication!,
.annotation: urlContext.options.annotation!
]
SCSDKLoginClient.application(UIApplication.shared, open: urlContext.url, options: options)
}
}
我在 SnapKitDevPortal 中设置了 URL 方案和重定向 URL。有人知道我做错了什么吗?提前致谢。
更新:找到解决方案 首先,如果使用 iOS 13,我必须在 SceneDelegate 中实现这段代码:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
for urlContext in URLContexts {
let url = urlContext.url
var options: [UIApplication.OpenURLOptionsKey : Any] = [:]
options[.openInPlace] = urlContext.options.openInPlace
options[.sourceApplication] = urlContext.options.sourceApplication
options[.annotation] = urlContext.options.annotation
SCSDKLoginClient.application(UIApplication.shared, open: url, options: options)
}
}
然后,在拔掉头发几个小时后,我发现了我在设置 info.plist 时犯的一个简单错误。在 Snapchat 的文档中,在“CFBundleURLSchemes”下,它说这应该包含值“myapp”。我不明白这是指 URL Scheme,而不是应用程序的名称。因此,如果您的应用程序名称是“mycoolapp”并且您的 URL 方案是“myapp://snapauth”,那么您应该将“myapp”放在“CFLBundleURLSchemes”下,而不是“mycoolapp”下。希望这可以帮助。
解决方案
更新:由于您已经有了 in 的实现openURL
,AppDelegate
您只需从 调用它SceneDelegate
,如下所示:
func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let url = URLContexts.first?.url else {
return
}
let _ = ApplicationDelegate.shared.application(
UIApplication.shared,
open: url,
sourceApplication: nil,
annotation: [UIApplication.OpenURLOptionsKey.annotation])
}
<array>
您需要在of下的 info.plist 文件中添加您希望应用打开的 url 方案LSApplicationQueriesSchemes
,如下所示:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>snapchat</string>
<array>
推荐阅读
- ios - IOS Swift 4 AppDelegate 应用程序处理接收自定义 URL AirDrop 文件未命中
- python - IF 表达式包含意外的数字 - 可以缩短代码
- r - 如何过滤掉R中的一个因素
- c++ - 如何使用指针 C++ 访问结构中的数组元素
- c# - 有没有办法将数据从被调用的天蓝色函数返回给调用它的逻辑应用程序?
- reactjs - 使用 React Native 和 useEffect 获取
- python - 编写程序求矩阵中所有偶数之和,并求矩阵的转置
- python - 使用 Python Tkinter 更改日历中单元格的背景?
- java - 定义和使用二维数组的语法错误
- c++ - 为什么递归深度是不确定的(C++)?