Hey all,
I've tried to add the SwiftyDropbox package into my SwiftUI iOS project and followed the GitHub readme:
I updated the following files as recommended using my app key:
- Info.plist
- AppDelegate.swift
I got stuck when implementing the Authentication Flow in my ContentView.swift:
are there any simple example projects using SwiftyDropbox with SwiftUI?
I get
1. a warning: 'openURL' was deprecated in iOS 10.0
2. errors:
-canOpenURL: failed for URL: "dbapi-2://1/connect?k=[MY_APP_KEY_:)]=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
-canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=[MY_APP_KEY_:)]=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"
[Presentation] Attempt to present <SwiftyDropbox.MobileSafariViewController: 0x15d00ea00> on <TestSwiftyDropbox.ViewController: 0x15be06540> (from <TestSwiftyDropbox.ViewController: 0x15be06540>) whose view is not in the window hierarchy.
ContentView.swift
struct ContentView: View {
var viewController = ViewController()
var body: some View {
VStack{
Text("Dropbox Test")
if DropboxClientsManager.authorizedClient != nil {
Button(action: {
DropboxClientsManager.unlinkClients() // logout()
}, label: {
Text("Dropbox Logout")
})
} else {
Button(action: {
viewController.authenticate()
}, label: {
Text("Dropbox Login") // Authorization
})
}
}
}
}
class ViewController: UIViewController {
func authenticate() {
// a) Legacy authorization flow that grants a long-lived token.
DropboxClientsManager.authorizeFromController(UIApplication.shared,
controller: self,
openURL: { (url: URL) -> Void in
UIApplication.shared.openURL(url)
})
// b) New: OAuth 2 code flow with PKCE that grants a short-lived token with scopes.
// DropboxClientsManager.authorizeFromControllerV2(
// UIApplication.shared,
// controller: self,
// loadingStatusDelegate: nil,
// openURL: { (url: URL) -> Void in UIApplication.shared.openURL(url) },
// scopeRequest: scopeRequest
// )
}
}
Any hints are appreciated as I am new to UIKit and just implemented everything with SwiftUI!
Best regard,
Fleaurent