SnapKit登录Snapchat后无法返回到应用程序 [英] SnapKit fails return to app after logging into Snapchat

查看:106
本文介绍了SnapKit登录Snapchat后无法返回到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Snapchat上进行身份验证失败后,我一直试图将Snapchat引导回我的应用程序.这是我在应用程序委托中拥有的代码,我认为它不起作用:

I have been trying to direct Snapchat back to my app after authenticating on Snapchat to no success. Here is the code I have in my app delegate which is where I think it is not working:

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.有人知道我在做什么错吗?预先感谢.

I have set up a URL Scheme and a Redirect URL in SnapKitDevPortal. Does anybody know what I am doing wrong? Thanks in advance.

更新:发现的解决方案首先,如果使用iOS 13,我必须在SceneDelegate中实现以下代码:

UPDATE: SOLUTION FOUND First, I had to implement this bit of code in the SceneDelegate if using iOS 13:

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方案,而不是应用程序的名称.因此,如果您的应用程序名称为"mycoolapp",而URL方案为"myapp://snapauth",则应将"myapp"放在"CFLBundleURLSchemes"下,而不是" ""mycoolapp"下.希望这会有所帮助.

Then, after hours of pulling out my hair, I found the simple mistake that I made while setting up my info.plist. In Snapchat's documentation, under "CFBundleURLSchemes", it says that this should contain the value "myapp". I did not understand that this was referring to the URL Scheme, and not the name of the app. So if your app name was "mycoolapp" and your URL Scheme was "myapp://snapauth", then you would put "myapp" under "CFLBundleURLSchemes", not "mycoolapp". Hope this helps.

推荐答案

更新:由于您已经在 AppDelegate 中实现了 openURL 的实现,因此只需从 SceneDelegate ,就像这样:

Update: Since you already have the implementation for openURL in AppDelegate you just need to call it from SceneDelegate, like this:

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])        
}

您需要在 LSApplicationQueriesSchemes < array> 下的info.plist文件中添加希望您的应用打开的url方案,如下所示:

You need to add the url scheme you want your app to open in the info.plist file under the <array> of LSApplicationQueriesSchemes, like this:

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>snapchat</string>
<array>

这篇关于SnapKit登录Snapchat后无法返回到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆