Почему перенаправление OAuth не работает в iOS 13, а в iOS 12? - PullRequest
0 голосов
/ 09 ноября 2019

Я разрабатываю свое приложение, которое должно взаимодействовать с Dropbox, скачать файл, прочитать и написать его, а затем загрузить его. Проблема в том, что приложение отлично работает в iOS 12, но не работает в iOS 13. Я думаю, что проблема здесь, потому что код не выполняется, а в симуляторе iOS 12 он есть.

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

это код в контроллере представления

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

, и это 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
    }

}

это мой 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>

Я положил печать («х»), чтобы понять, был ли выполнен код, и я заметил, что в ios12 все в порядке, в iOS 13 не работает. Есть идеи?

1 Ответ

1 голос
/ 14 ноября 2019

Добавить эту функцию в 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)")
              }
          }

      }
  }
...