We’re Still Here to Help (Even Over the Holidays!) - find out more here.
Forum Discussion
Mull999
2 years agoExplorer | Level 3
SwiftyDropbox
I am attempting to integrate Dropbox into my SwiftUI project. In the AppDelegate func(application...) I am getting an error stating that setupWithAppKey(<APP_KEY>) is not a member type of DropboxClient Manager. Any ideas on how to resolve>
9 Replies
- iNeil2 years ago
Dropbox Community Moderator
Hi Mull999,
I'll be happy to help with any issues you're having with the Dropbox Swift SDK, but I'll need some more information. Please reply with:
- the name and version of the platform and SDK/library you are using
- the steps to reproduce the issue, including relevant code snippet(s), but don't include any access or refresh token(s)
- the full text of any error or unexpected output - Mull9992 years agoExplorer | Level 3
Hi iNeil
Thanks for responding. I should say at the outset that I am a hobby coder and very much in learning mode. I have a shopping list app that works as intended and now I want to be able to file the data as backup using my Dropbox files. So I have started to build a test app to learn how to get access to Dropbox through a SwiftUI app. I read the advice given on Github SwiftyDropbox version10.0. and implemented the requirements
I successfully attached the package SwiftyDropbpox 10.0.7 to my test app. However I get an error in my AppDelegate, as follows:-
func application(_application: UIApplication, didFinishLaunchingWithOptions launchOptions: DropboxClientsManager.setupWithAppKey("<APP_KEY>") -> Bool { return true }
The error says setupWithAppKey is not a member type of DropboxClientsManager.
The app fails at that point so I have not got further into testing. However, I am thinking perhaps the SwiftyDropbox package is not compatible with SwiftUI.
I hope you can offer some advice.
- Greg-DB2 years ago
Dropbox Community Moderator
Thanks for following up. It should be possible to use SwiftyDropbox in a SwiftUI project. The SwiftyDropbox readme does have some notes throughout about how to use it in SwiftUI.
For reference, how did you install the SwiftyDropbox package?
Also, do you have 'import SwiftyDropbox' in your AppDelegate?
Finally, is that the actual 'func application...' code you have? It looks like it may be a copy/paste mistake, as it doesn't appear to be a valid definition (e.g., it's missing a ")", etc.). I believe it should look something like this:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { DropboxClientsManager.setupWithAppKey("<APP_KEY>") return true } - Mull9992 years agoExplorer | Level 3
Hi Greg
I used Apple Package Manager to integrate SwiftyDropbox into my test app. Yes I have the import statement in the AppDelegate.
I replaced my func application(...) with your version above and that had a positive result. The app still failed but at a location inside the SwiftyDropbox package.
I cannot find a way to insert a screen shot of the point of failure - my inexperience I guess (still learning at 80 years old!!!). However the fail is in the DropboxClientsManager extension within the init() in this line of code :-
self.dauthRedirectURL = URL(string: "db-\(appKey)://1/connect")!
Fail message is Unexpectedly found nil while unwrapping an Optional.
I have got the appKey in the infoplist as per the instructions in SwiftyDropbox so I am not sure what is causing this problem
- Greg-DB2 years ago
Dropbox Community Moderator
This particular error should depend on the app key value you pass to setupWithAppKey (not the instance you set in the plist).
Can you confirm you're passing your app key (and just the app key) to DropboxClientsManager.setupWithAppKey? Note that <APP_KEY> is just a placeholder for demonstration purposes, and you should not include the angle brackets in your actual code. (If you include the angle brackets, or other invalid characters, that would result in an invalid URL string which would cause the URL initializer to return nil which would cause the unwrapping error you're getting.)
To be clear, it would look like this:
DropboxClientsManager.setupWithAppKey("abc123")where abc123 would be replaced with your actual app key.
- Mull9992 years agoExplorer | Level 3Hi Greg, sorry for the radio silence but Xcode decided to update the simulator which then refused to boot. However, taking your last advice and running the app on my iPhone I got to the opening screen asking to login to Dropbox. Progress. Unfortunately there seems to be a problem in the plist scheme which I will try to resolve. The appkey is not recognised. I will let you know how I get on with both these issues. I do enjoy coding but it drives me crazy sometimes
- Mull9992 years agoExplorer | Level 3
Hi Greg
OK, solved the issue with Xcode and simulators. The issue I have with SwiftyDropbox has now moved on to the logon. I get a message saying I need to add identifier to the URL Types. When I add URL Types in the infoList I have
What to type into Identifier and URL Schemes?
Richard
- Mull9992 years agoExplorer | Level 3
Greg
Ignore my last message, I have resolved those issues and I can now login to my Dropbox account. What I don't understand is how to programatically access my App folder and then how to create a new folder. Reading Github I see a construct like:
client.files.createFolder(path: "\test\path\in\Dropbox\account". response etc
My question is what will my path be, the above looks like a generalised example.
- Greg-DB2 years ago
Dropbox Community Moderator
It looks like you're referring to this example here. That does show a made up example path, but note that paths in Dropbox use "/" as the path separator like shown in that example, not "\".
Paths in Dropbox will be relative to some root, based on the app and configuration. For apps with the app folder access type, the paths are automatically relative to the app folder. So, if you want to make a folder named "NewFolder" inside the app folder, you would supply a path of "/NewFolder". If you wanted to list the contents of that new folder (which would be empty initially), you would start by supplying a path of "/NewFolder" to listFolder. Or to start listing the contents of the app folder itself, you would supply a path of the empty string "" to listFolder.
The File Access Guide may be helpful to review for more information on how to interact with files and folders on the Dropbox API.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!