Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
Bob S.15
9 years agoCollaborator | Level 9
DropboxClientsManager authorizeFromController not doing anything
Hello,
I'm having trouble presenting the Dropbox login to the user. I had it working some time ago, but today I tried it and nothing happens. I make this call and nothing happens.
...
- 9 years ago
Hey Greg,
Finally found it. I was skipping the call to DBClientsManager setupWithAppKey! It was in there, but I was mistakenly skipping it when my app had stored the preference that Dropbox was disconnected. It's weird that that produces no error messages. I found the problem by stepping in the debugger into authorizeFromController and noticing that both my sharedApplication and controller arguments were 'nil', even though they were valid values when I passed them. Then I noticed the assert in that function:
NSAssert([DBOAuthManager sharedOAuthManager] != nil, @"Call `Dropbox.setupWithAppKey` or `Dropbox.setupWithTeamAppKey` before calling this method");As soon as I saw that, I knew what I had done.
I guess that the assert never fired, because [DBOAuthManager sharedOAuthManager] is a valid number even if you have not called setupWithAppKey?
Anyway thanks for helping me with this problem, I really appreciate it. I'll probably run into more but at least this one is down.
Bob
Greg-DB
Dropbox Community Moderator
9 years agoThere have been some breaking changes to the SDK over the various updates. (The SDKs mostly use Semantic Versioning to indicate breaking changes/feature updates/bug fixes.) If you're updating from an old version, you'll need to update your code for those changes. You can find more information in the release log.
Bob S.15
9 years agoCollaborator | Level 9
I don't understand -- this is just from trying to update the SDK. I have not even gotten to trying to open and compile my own project yet. The standalone SDK did download and update correctly, however.
- Greg-DB9 years ago
Dropbox Community Moderator
Oh, apologies, I didn't realize the second part was still Carthage output. Yes, in that case, please try removing the entire Carthage build of the SDK in that app and re-installing it. - Bob S.159 years agoCollaborator | Level 9
Okay. The Example app works fine.
I deleted the sdk's from my apps and re-downloaded. They update fine now.
I read the release notes, though -- you dropped support for iOS 8? So iOS9+ only? Too soon! I'm only just now dropping 7.
I set my cartfile to 3.0.11 which looks to be the one before you dropped iOS 8 support. Should that work, or have I got to drop 8 to continue using Dropbox?
But my god there are sure a lot of changes since I was working on this just a couple of months ago.
Here's one error I see a few times: "instance method -progress not found". This is in case like this one, where I was downloading a file:
[[[[DBClientsManager authorizedClient].filesRoutes downloadUrl:remotePath overwrite:NO destination: destURL] setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *downloaderror, DBRequestError *error, NSURL *destination) { if (result) { NSLog(@"%@\n", result); [brainpan loadedDropboxFile]; } else { [brainpan loadDropboxFileFailed:(int)downloaderror.tag]; } }] progress:^(int64_t bytesUploaded, int64_t totalBytesUploaded, int64_t totalBytesExpectedToUploaded) { NSLog(@"\n%lld\n%lld\n%lld\n", bytesUploaded, totalBytesUploaded, totalBytesExpectedToUploaded); }];If I look at the API documentation, the example for downloading a file looks a lot like mine:
http://dropbox.github.io/dropbox-sdk-obj-c/api-docs/latest/index.html#download-style-request
[[[client.filesRoutes downloadUrl:@"/test/path/in/Dropbox/account" overwrite:YES destination:outputUrl] setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError, NSURL *destination) { if (result) { NSLog(@"%@\n", result); NSData *data = [[NSFileManager defaultManager] contentsAtPath:[destination path]]; NSString *dataStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"%@\n", dataStr); } else { NSLog(@"%@\n%@\n", routeError, networkError); } }] progress:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) { NSLog(@"%lld\n%lld\n%lld\n", bytesDownloaded, totalBytesDownloaded, totalBytesExpectedToDownload); }];Can you tell what I am doing wrong from what I've listed here?
Also, has the process for getting and saving OAuth2Tokens from OAuth1Tokens changed? That function you gave me, "
getAndSaveOAuth2TokensFromRetrievedOAuth1Tokens" has some errors, and in the documentation it looks like there is a whole new way of doing this: https://github.com/dropbox/dropbox-sdk-obj-c#migrating-oauth-tokens-from-earlier-sdks
Man this is kind of overwhelming, did I just pick the absolute wrong time to upgrade Dropbox back in January, like a week before you guys decided to change everything in the SDK?
Thanks
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
Yes, unfortunately we had to drop support for iOS 8. (This is because we are moving to Safari View Controller, in order to better support the Google Sign In flow, which no longer allows web views: https://developers.googleblog.com/2016/08/modernizing-oauth-interactions-in-native-apps.html , among other features.)
You can technically use an older version of the SDK, but it's not reccomended. (E.g., the Google Sign In flow will stop working in the web view, though you can make sure you set browserAuth:YES to support that.)
Anyway, apologies there were a lot of changes! You can find information in the release log. For example, "progress" changed to "setProgressBlock", and "response" changed to "setResponseBlock".
And yes, you can now use checkAndPerformV1TokenMigration, which we more recently built in to the SDK, using the same mechanisms we discussed earlier this year when working out getAndSaveOAuth2TokensFromRetrievedOAuth1Tokens with you.
- Bob S.159 years agoCollaborator | Level 9
I think part of the problem is that the documentation has not kept up with the changes -- for example, the release notes state that the browserAuth argument was dropped from authorizeFromController, but the API reference still lists it.
And the example for how to download a file shows 'setResponseBlock', but it does NOT show 'setProgressBlock'. It still says 'progress'.
This is especially important since that demo describes how to call that whole class of functions and that's the only place I have found where it is demonstrated. It's not even part of the function definitions themselves. First of all there's no easy way to find the actual function definitions. Like WHERE is the function definition for 'downloadURL'? It is such an important function, yet searching for it from the main API page doesn't reveal it. To find that function I have to look at my code, see that DBClientsManager has a member called authorizedClient, which is of type DBUserClient. Click that and then click on DBUserBaseClient when you don't see filesRoutes listed. Only then can you find that filesRoutes is of type DBFILESUserAuthRoutes, click on it and finally find the function definition for downloadURL. But even then, there is nothing on the documentation page for downloadURL which suggests that it must be called with extra arguments 'setResponseBlock' and 'setProgressBlock'! How is someone supposed to know that?!
Sorry for the rant -- but the API page could really use a search function, and those functions which require response and progress block arguments should say that.
Anyway, I got everything compiled in both of my apps and am back to square one. I've got one app which works fine, and the other one just ignores the calls to authorize the user.
- Greg-DB9 years ago
Dropbox Community Moderator
Thanks for pointing out the old examples! We'll get that fixed up in the documentation.
And thanks for the rest of the feedback on the documentation! It's much appreciated.
Anyway, regarding the issue of authorizeFromController not working, since it's working in your other app and the sample app, it seems like the issue must be specific to that one app. To make sure of that though, can you confirm if you tested the working apps on the same device as the not working app? Also, to eliminate other variables, do you have the same version of the SDK installed in both?
Finally, it would be helpful if we could reproduce the issue. Is the problematic app available in the US App Store for us to try?
- Bob S.159 years agoCollaborator | Level 9
Yes, it must be something specific to this app. This app is from 2008 and has some very old funky viewController stuff going on -- so I suspect it has something to do with that. It may be due to recent iOS SDK changes rather than Dropbox SDK stuff. But yeah I am testing on the same devices and simulators, same SDK version.
The app is in the store but it doesn't have the new Dropbox SDK stuff. The one in the store is still using the old API v1.
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
Thanks! If it is due to an unusual view controller setup it's unlikely we'll be able to help without seeing more code. Would you be able to share the relevant code, and send us a build we can try? You can write in privately here if you'd prefer:
https://www.dropbox.com/developers/contact - Bob S.159 years agoCollaborator | Level 9
Man, you do not want to see this code. It is like a building that people have added multiple floors to, with extra sheds and carparks and a kitchen in back. I would be ashamed to show it to anyone, and it is freaking huge too.
The one thing that makes me think it doesn't have to do with viewControllers, however, is that in the other app, the one that works, it doesn't open a viewController when I authorize. It opens the Dropbox app. So I assume this broken app would do the same thing.
- Bob S.159 years agoCollaborator | Level 9
Greg how do I determine which version of the SDK I have? I set my Cartfile to ~> 3.0.11, but I just noticed that in the shell when I run the update, it says Checking out dropbox-sdk-obj-c at "3.0.14". I am compiling with a deployment target of 8.0 and not getting any errors -- does that mean it would just crash on an iOS 8 machine or just not connect?
- Greg-DB9 years ago
Dropbox Community Moderator
You don't have to share your code if you don't want to, but for what it's worth, we won't judge your code! :-)
If the view controller setup seems unlikely to be the problem, perhaps it's something to do with the UIApplication? Is there anything unusual about your [UIApplication sharedApplication] in that app?
In any case, if it helps, the SDK is open source so you can see the definition for authorizeFromController here:
But yes, with the broken app we would also expect the official Dropbox app to get launched if it's installed. It checks if the app is installed first using canOpenUrl via the passed along UIApplication, and then opens it using openUrl, if so. It's possible it's failing somewhere there, but I've always seen output when something goes wrong with that.
Also, as another data point, have you tried it on multiple devices?
And you can programmatically check the SDK version using the kV2SDKVersion constant. Or, you can check the installed version manually in the Cartfile.resolved file. The "~>" Carthage operator is how you request a "compatible" version, so "~> 3.0.11" will give you "3.0.14", for example.
I'm not sure offhand what the expected failure mode is when attempting to use it on iOS 8, but I would expect it to crash, at least during the app authorization flow if not at launch.
- Bob S.159 years agoCollaborator | Level 9
I see. So what would I put in the CartFile to make it download version 3.0.11, to continue supporting iOS 8?
- Greg-DB9 years ago
Dropbox Community Moderator
Based on the Cartfile documentation, it looks like the operator for that is "==", so you'd need "== 3.0.11".
- Bob S.159 years agoCollaborator | Level 9
Hey Greg,
Finally found it. I was skipping the call to DBClientsManager setupWithAppKey! It was in there, but I was mistakenly skipping it when my app had stored the preference that Dropbox was disconnected. It's weird that that produces no error messages. I found the problem by stepping in the debugger into authorizeFromController and noticing that both my sharedApplication and controller arguments were 'nil', even though they were valid values when I passed them. Then I noticed the assert in that function:
NSAssert([DBOAuthManager sharedOAuthManager] != nil, @"Call `Dropbox.setupWithAppKey` or `Dropbox.setupWithTeamAppKey` before calling this method");As soon as I saw that, I knew what I had done.
I guess that the assert never fired, because [DBOAuthManager sharedOAuthManager] is a valid number even if you have not called setupWithAppKey?
Anyway thanks for helping me with this problem, I really appreciate it. I'll probably run into more but at least this one is down.
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
Great! I'm glad to hear you tracked this down. I'll ask the team to see if we can make this fail more noisily in that case. - Greg-DB9 years ago
Dropbox Community Moderator
I'm trying to reproduce this, but in my simple test project I am getting that assert exception thrown when omitting setupWithAppKey and then calling authorizeFromController.
To help us reproduce this, do you know how your app got into a state where [DBOAuthManager sharedOAuthManager] wasn't nil? What was the value of [DBOAuthManager sharedOAuthManager] in that case? - Bob S.159 years agoCollaborator | Level 9
Hey Greg,
Well, I could swear I checked the value of sharedOAuthManager and it was nonzero, but now it shows zero when I do not call setupWithAppKey. However, it doesn't make any difference - even when it is zero, I still don't see any error message. I tried it with DBRoulette and got the same results.
What happens for you when that assert fires? Does that text print out in the console?
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
I do get an exception thrown with the message:
*** Assertion failure in +[DBClientsManager authorizeFromController:controller:openURL:], test_project/Pods/ObjectiveDropboxOfficial/Source/ObjectiveDropboxOfficial/Platform/ObjectiveDropboxOfficial_iOS/DBClientsManager+MobileAuth-iOS.m:20 2017-04-19 11:40:19.423 test_project[44538:72659315] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Call `Dropbox.setupWithAppKey` or `Dropbox.setupWithTeamAppKey` before calling this method' *** First throw call stack: ( 0 CoreFoundation 0x000000010e14ab0b __exceptionPreprocess + 171 1 libobjc.A.dylib 0x000000010d50c141 objc_exception_throw + 48 2 CoreFoundation 0x000000010e14ecf2 +[NSException raise:format:arguments:] + 98 3 Foundation 0x000000010b63a3b6 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193 4 test_project 0x000000010b01bb69 +[DBClientsManager(MobileAuth) authorizeFromController:controller:openURL:] + 393 5 test_project 0x000000010b011a3f -[ViewController didPressLink:] + 223 6 UIKit 0x000000010bca9d22 -[UIApplication sendAction:to:from:forEvent:] + 83 7 UIKit 0x000000010be2e25c -[UIControl sendAction:to:forEvent:] + 67 8 UIKit 0x000000010be2e577 -[UIControl _sendActionsForEvents:withEvent:] + 450 9 UIKit 0x000000010be2d4b2 -[UIControl touchesEnded:withEvent:] + 618 10 UIKit 0x000000010bd1749a -[UIWindow _sendTouchesForEvent:] + 2707 11 UIKit 0x000000010bd18bb0 -[UIWindow sendEvent:] + 4114 12 UIKit 0x000000010bcc57b0 -[UIApplication sendEvent:] + 352 13 UIKit 0x000000010c4a8adc __dispatchPreprocessedEventFromEventQueue + 2926 14 UIKit 0x000000010c4a0a3a __handleEventQueue + 1122 15 CoreFoundation 0x000000010e0f0c01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 16 CoreFoundation 0x000000010e0d60cf __CFRunLoopDoSources0 + 527 17 CoreFoundation 0x000000010e0d55ff __CFRunLoopRun + 911 18 CoreFoundation 0x000000010e0d5016 CFRunLoopRunSpecific + 406 19 GraphicsServices 0x0000000113a2ba24 GSEventRunModal + 62 20 UIKit 0x000000010bca80d4 UIApplicationMain + 159 21 test_project 0x000000010b01220f main + 111 22 libdyld.dylib 0x000000010effa65d start + 1 23 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException - Bob S.159 years agoCollaborator | Level 9
Huh - I don't get anything. I wonder if I have exceptions turned off somehow?
- Bob S.159 years agoCollaborator | Level 9
I tried putting that exception in the main body of DBRoulette, right after the commented out setupWithAppKey line, and it terminated with the same error you got. But it doesn't seem to fire within the SDK library. Probably unrelated, but it also seems weird to me that when I step into that function, my controller and [UIApplication sharedApplication] arguments show up as nil in the debugger.
- Bob S.159 years agoCollaborator | Level 9
Hey Greg, here is my DBRoulette project, in case you want to try it out. I'd be curious to know whether the assert fires for you.
https://www.dropbox.com/s/teyv6nmhhyfmzyu/dropbox-sdk-obj-c-master.zip?dl=0
- Greg-DB9 years ago
Dropbox Community Moderator
This project does not fire the assert for me. It does print:
yah 0 yah 0
What's different in this project? Did you change a project setting or is it something in the code?
- Bob S.159 years agoCollaborator | Level 9
Hey Greg,
As far as I know, there is nothing different about the project. I just added the print statements to print out the value of sharedOAuthManager. That's the standalone project you linked to earlier in this thread.
Bob
- Greg-DB9 years ago
Dropbox Community Moderator
Interesting. In that case I'll dig into it further now that I can reproduce it. Thanks! - Greg-DB9 years ago
Dropbox Community Moderator
Ok, I determined what the issue is here. Whether or not the assert occurred depended on the ENABLE_NS_ASSERTIONS build setting. By default, that build setting varies depending on which scheme you're building for. (It's Debug:Yes, Release:No.)
When using Cocoapods (as I often do when testing things) the scheme used for the Dropbox library is whatever scheme you're building your project with. While developing an app, that's typically the Debug scheme.
When using Carthage however, the Dropbox library is built when you run `carthage`, which by default uses the Release scheme. (This is configurable using Carthage's `--build` setting.)
These differences are what caused the inconsistency when trying to reproduce this across projects (since it depended on the setting/scheme/installation method.)
We're going to change this assert into a log statement so that it will happen irrespective of these conditions.
Thanks for your help and patience tracking this down! - Bob S.159 years agoCollaborator | Level 9
Ah, that makes sense. Thanks for helping me find the problem in my app!
Bob
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!