<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: SwiftyDropbox SwiftUI iOS in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500712#M24826</link>
    <description>&lt;P&gt;Unfortunately the SwiftyDropbox SDK wasn't built for or tested with SwiftUI, so we don't have any resources or examples for that. I'll pass this along as a request for official support for that, but I can't promise if/when that would be done.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Mar 2021 16:03:47 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2021-03-01T16:03:47Z</dc:date>
    <item>
      <title>SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500357#M24819</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;
&lt;P&gt;I've tried to add the SwiftyDropbox package&amp;nbsp;into my SwiftUI iOS project and followed the GitHub readme:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I updated the following files as recommended using my app key:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Info.plist&lt;/P&gt;
&lt;P&gt;- AppDelegate.swift&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I got stuck when implementing the Authentication Flow in my ContentView.swift:&lt;/P&gt;
&lt;P&gt;are there any simple example projects using SwiftyDropbox with SwiftUI?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I get&lt;/P&gt;
&lt;P&gt;1. a warning: 'openURL' was deprecated in iOS 10.0 &amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. errors:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;-canOpenURL: failed for URL: "dbapi-2://1/connect?k=[MY_APP_KEY_:)]=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;-canOpenURL: failed for URL: "dbapi-8-emm://1/connect?k=[MY_APP_KEY_:)]=" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;[Presentation] Attempt to present &amp;lt;SwiftyDropbox.MobileSafariViewController: 0x15d00ea00&amp;gt; on &amp;lt;TestSwiftyDropbox.ViewController: 0x15be06540&amp;gt; (from &amp;lt;TestSwiftyDropbox.ViewController: 0x15be06540&amp;gt;) whose view is not in the window hierarchy.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ContentView.swift&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="cpp"&gt;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) -&amp;gt; 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) -&amp;gt; Void in UIApplication.shared.openURL(url) },
//              scopeRequest: scopeRequest
//          )
    }
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any hints are appreciated as I am new to UIKit and just implemented everything with SwiftUI!&lt;/P&gt;
&lt;P&gt;Best regard,&lt;/P&gt;
&lt;P&gt;Fleaurent&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 06:44:30 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500357#M24819</guid>
      <dc:creator>Fleaurent</dc:creator>
      <dc:date>2021-03-01T06:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500712#M24826</link>
      <description>&lt;P&gt;Unfortunately the SwiftyDropbox SDK wasn't built for or tested with SwiftUI, so we don't have any resources or examples for that. I'll pass this along as a request for official support for that, but I can't promise if/when that would be done.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 16:03:47 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500712#M24826</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2021-03-01T16:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500793#M24829</link>
      <description>&lt;P&gt;OK, thank you for the response!&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 20:04:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/500793#M24829</guid>
      <dc:creator>Fleaurent</dc:creator>
      <dc:date>2021-03-01T20:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/502568#M24867</link>
      <description>&lt;P&gt;I found the following &lt;A href="https://github.com/dropbox/SwiftyDropbox/issues/266" target="_self"&gt;issue&lt;/A&gt; regarding SwiftyDropbox and SwiftUI:&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just removed the ScrollView which made Problems, and it seems to work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;struct ContentView : View {
    @State var isShown = false
    
    var body : some View {
            VStack {
                Text("HI!")
                Button(action: {
                    self.isShown.toggle()
                }) {
                    Text("Dropbox....")
                }
                DropboxView(isShown: $isShown)
            }
    }
}


struct DropboxView: UIViewControllerRepresentable {
    typealias UIViewControllerType = UIViewController
    
    @Binding var isShown : Bool

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        if isShown {
            DropboxClientsManager.authorizeFromController(UIApplication.shared,
            controller: uiViewController,
            openURL: { (url: URL) -&amp;gt; Void in
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            })
        }
    }

    func makeUIViewController(context _: Self.Context) -&amp;gt; UIViewController {
        return UIViewController()
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;--&amp;gt; the authorisation page of Dropbox opens and I can enter my credentials.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My next Problem: when I check the DropcoxClientsManager afterwards, it still contains nil&lt;/P&gt;&lt;PRE&gt;if DropboxClientsManager.authorizedClient != nil {&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Mar 2021 17:39:58 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/502568#M24867</guid>
      <dc:creator>Fleaurent</dc:creator>
      <dc:date>2021-03-07T17:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/529315#M25615</link>
      <description>&lt;P&gt;Fleaurent,&lt;/P&gt;&lt;P&gt;&amp;nbsp; Thank you for being a pioneer of Dropbox and SwiftUI. &amp;nbsp;I've just started playing around with this kit in swiftUI and I'm wondering if you got past your last issue the client manager being nil? &amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Sat, 26 Jun 2021 20:07:16 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/529315#M25615</guid>
      <dc:creator>aspiguel</dc:creator>
      <dc:date>2021-06-26T20:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/584283#M27204</link>
      <description>&lt;P&gt;Has anyone been able to solve DropboxClientsManager.authorizedClient always equal to nil with SwiftUI?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Mar 2022 17:41:09 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/584283#M27204</guid>
      <dc:creator>himike12</dc:creator>
      <dc:date>2022-03-17T17:41:09Z</dc:date>
    </item>
    <item>
      <title>Re: SwiftyDropbox SwiftUI iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/584571#M27217</link>
      <description>&lt;P&gt;I have successfully authenticated authenticated with SwiftyDropbox using SwiftUI. I hope that this is useful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Setup info.plist as the SwiftyDropbox&amp;nbsp; readme instructs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;lt;app name&amp;gt;.swift&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;import SwiftUI
import SwiftyDropbox

@main
struct DropboxTestApp: App {

    init() {
        DropboxClientsManager.setupWithAppKey("&amp;lt;app key&amp;gt;")
    }
    
    var body: some Scene {
        WindowGroup {
            ContentView()
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ContentView.swift&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;import SwiftUI
import SwiftyDropbox

struct ContentView: View {
    
    @State var isShown = false
    
    var body: some View {
        VStack {
            
            Button(action: {
                self.isShown.toggle()
            }) {
                Text("Login to Dropbox")
            }

            DropboxView(isShown: $isShown)
            
            Button {
                if let client = DropboxClientsManager.authorizedClient {
                    print("successful login")
                } else {
                    print("Error")
                }
            } label: {
                Text("Test Login")
            }
            
        }
        .onOpenURL { url in
            let oauthCompletion: DropboxOAuthCompletion = {
                if let authResult = $0 {
                    switch authResult {
                    case .success:
                        print("Success! User is logged into DropboxClientsManager.")
                    case .cancel:
                        print("Authorization flow was manually canceled by user!")
                    case .error(_, let description):
                        print("Error: \(String(describing: description))")
                    }
                }
            }
            DropboxClientsManager.handleRedirectURL(url, completion: oauthCompletion)
        }
    }
}

struct DropboxView: UIViewControllerRepresentable {
    typealias UIViewControllerType = UIViewController
    
    @Binding var isShown : Bool
    
    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {
        
        if isShown {
            let scopeRequest = ScopeRequest(scopeType: .user, scopes: ["account_info.read", "files.metadata.write", "files.metadata.read", "files.content.write", "files.content.read"], includeGrantedScopes: false)
            DropboxClientsManager.authorizeFromControllerV2(
                UIApplication.shared,
                controller: uiViewController,
                loadingStatusDelegate: nil,
                openURL: { (url: URL) -&amp;gt; Void in UIApplication.shared.open(url, options: [:], completionHandler: nil) },
                scopeRequest: scopeRequest)
        }
    }
    
    func makeUIViewController(context _: Self.Context) -&amp;gt; UIViewController {
        return UIViewController()
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You do not need create an AppDelegate.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 17:31:52 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/SwiftyDropbox-SwiftUI-iOS/m-p/584571#M27217</guid>
      <dc:creator>himike12</dc:creator>
      <dc:date>2022-03-18T17:31:52Z</dc:date>
    </item>
  </channel>
</rss>

