简体   繁体   English

为什么 OAuth 重定向在 iOS 13 中不起作用,但在 iOS 12 中起作用?

[英]Why does OAuth redirect not work in iOS 13 but it does in iOS 12?

I'm developing my app which should interact with dropbox, download a file, read and write it and then upload it.我正在开发我的应用程序,它应该与 Dropbox 交互、下载文件、读取和写入然后上传。 The problem is that the app works fine in iOS 12 but doesn't work in iOS 13. I think the problem is here because the code is not executed and in the iOS 12 simulator it is.问题是该应用程序在 iOS 12 中运行良好,但在 iOS 13 中不起作用。我认为问题出在此处,因为代码未执行,而在 iOS 13 中它是模拟器。1

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

this is the code in view controller这是视图 controller 中的代码

import UIKit
import Foundation
import SwiftyDropbox

class viewCon:UIViewController {

    @IBOutlet weak var lab: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    @IBAction func refresh(_ sender: Any) {
        let client = DropboxClientsManager.authorizedClient
        if client == nil { lab.text = "Not logged"} else {lab.text = "Logged"}
    }

    @IBAction func login(_ sender: Any) {
        DropboxClientsManager.authorizeFromController(UIApplication.shared, controller:self, openURL: { (url: URL) -> Void in UIApplication.shared.open(url)})
    }


    @IBAction func download(_ sender: Any) {
    }
}

and this is AppDelegate.swift这是 AppDelegate.swift

import UIKit
import SwiftyDropbox

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        print("init")
        DropboxClientsManager.setupWithAppKey("********")
        // Override point for customization after application launch.
        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print("1")
        if let authResult = DropboxClientsManager.handleRedirectURL(url as URL) {
            print("2")
            switch authResult {
            case .success(_): //(let token)
                //print("Success! User is logged into Dropbox with token: \(token)")
                print("Success! User is logged into Dropbox.")
            case .cancel:
                print("User canceld OAuth flow.")
            case .error(let error, let description):
                print("Error \(error): \(description)")
            }
        } else {
            print("3")
        }
        return true
    }

}

this is my info.plist这是我的 info.plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>db-*********</string>
            </array>
        </dict>
    </array>
    <key>CFBundleVersion</key>
    <string>1</string>
    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>dbapi-8-emm</string>
        <string>dbapi-2</string>
    </array>

I put print("x") to understand if the code was executed and I noticed that in ios12 is all right, in iOS 13 does not work.我输入 print("x") 以了解代码是否已执行,我注意到在 ios12 中是可以的,在 iOS 13 中不起作用。 Any ideas?有任何想法吗?

Add this func in SceneDelegate在 SceneDelegate 中添加这个函数

 func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
      for urlContext in URLContexts {
          let url = urlContext.url

          if let authResult = DropboxClientsManager.handleRedirectURL(url) {
              switch authResult {
              case .success:
                  print("Success! User is logged into account.")

              case .cancel:
                  print("Authorization flow was manually canceled by user!")
              case .error(_, let description):
                  print("Error: \(description)")
              }
          }

      }
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 iOS 13 中没有调用 OpenUrl(),但在 iOS 12 中调用它。(Xamarin.ios) - Why does OpenUrl() is not being called in iOS 13 but it does in iOS 12.(Xamarin.ios) ISBX/apprtc-ios 在 iOS 13 上不起作用 - 没有视频不起作用 - ISBX/apprtc-ios does not work on iOS 13 - no video not working 为什么通用链接适用于 iOS 12,但不适用于 iOS 13? - Why Universal links works on iOS 12, but doesn't work on iOS 13? Google SignIn SDK(OAuth)如何重定向回iOS应用? - How does Google SignIn SDK (OAuth) redirect back to iOS app? TabView 在 iOS13 SwiftUI 上无法正常工作 - TabView does not work correctly on iOS13 SwiftUI web VR 模式在 iOS13 上的 Safari 中不再工作吗? - Does web VR mode no longer work in Safari on iOS13? iOS 13 提醒应用程序 url 方案不起作用 - iOS 13 reminders app url scheme does not work 为什么在 iOS 13 上更改 UILabel 的文本不会重置文本属性? - Why does changing the text of a UILabel not reset text attributes on iOS 13? 为什么 flex 项目在 iOS 13 中被拉伸? - Why does flex item get stretched iOS 13? 为什么 iOS 13 上的 UITabBarItem 中的 gif 图像显示蓝色? - Why does gif Image In UITabBarItem on iOS 13 show blue color?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM