dropbox-sdk-obj-c
dropbox-sdk-obj-c copied to clipboard
iOS 11.2.2 cant download files from Dropbox in last (3.4.0) ObjectiveDropboxOfficial SDK
I try download simple zip file from Dropbox to devices. But see the error:
DropboxClientError[{
NSError = "Error Domain=NSCocoaErrorDomain Code=513 \"\U201cCFNetworkDownload_aKHDTE.tmp\U201d couldn\U2019t be moved because you don\U2019t have permission to access \U201ctmp\U201d.\" UserInfo={NSSourceFilePathErrorKey=/var/mobile/Library/Caches/com.apple.nsurlsessiond/Downloads/<app>/CFNetworkDownload_aKHDTE.tmp, NSUserStringVariant=(\n Move\n), NSDestinationFilePath=/private/var/mobile/Containers/Data/Application/802158E7-6B2A-483F-BBFB-861D0F8EDE3A/tmp/D6B99CC4-6F71-4B32-9129-779784AFB60E, NSFilePath=/var/mobile/Library/Caches/com.apple.nsurlsessiond/Downloads/<app>/CFNetworkDownload_aKHDTE.tmp, NSUnderlyingError=0x109756820 {Error Domain=NSPOSIXErrorDomain Code=1 \"Operation not permitted\"}}";
}];
My code:
id currentTask = [userClient.filesRoutes downloadUrl:backupMetadata.pathLower overwrite:YES destination:outputURL];
[[(DBDownloadUrlTask*)currentTask setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError, NSURL *destination) { .. }];
For previous iOS version framework work fine. Checked in 10.3.3.
Thanks for the report. Can you let me know:
- are you seeing this on device or on simulator?
- are you seeing this on multiple devices/simulators, or only one in particular?
- are you seeing this in an app extension context?
- are you using
forceForegroundSession?
- on device, i have only one device with iOS 11.2.2.
- on simulators work fine, and not work on the device.
- not quite sure that I understand correctly what you are talking about
- no. just execute code like in examples.
more code:
DBUserClient *userClient = [DBClientsManager authorizedClient];
NSString *outputFileName = [NSString stringWithFormat:@"%@.backup", [NSUUID UUID].UUIDString];
NSURL *outputDirectory = [[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask][0];
NSURL *outputURL = [outputDirectory URLByAppendingPathComponent:outputFileName];
self.currentTask = [userClient.filesRoutes downloadUrl:backupMetadata.pathLower overwrite:YES destination:outputURL];
__weak typeof(self) weakSelf = self;
[[(DBDownloadUrlTask*)self.currentTask setResponseBlock:^(DBFILESFileMetadata *result, DBFILESDownloadError *routeError, DBRequestError *networkError, NSURL *destination) {
if (result)
{
}] setProgressBlock:^(int64_t bytesDownloaded, int64_t totalBytesDownloaded, int64_t totalBytesExpectedToDownload) {
}];
Thanks! Given that, I'm not aware of any reason this should be failing like this with the latest release of the SDK. (Can you double check that you do have the latest version, currently v3.4.0, installed?)
I just tried this code on a device running iOS 11.2.2 and it ran without issue.
I've used in podfile the line: pod 'ObjectiveDropboxOfficial', '~> 3.4.0' I've removed workspace and pods. I install pods again but still see the problem on my device.
Did the pod install complete successfully? Please check the Podfile.lock file to check what version actually got installed. I just want to double check since I know earlier versions of the SDK had issues like this that were fixed in more recent versions. Thanks!
pod install operation completed successful. Podfile.lock:
PODS:
- ObjectiveDropboxOfficial (3.4.0)
DEPENDENCIES:
- ObjectiveDropboxOfficial (~> 3.4.0)
SPEC CHECKSUMS: ObjectiveDropboxOfficial: 250ce53218773ba687201614ad6de03b8cb14de6
PODFILE CHECKSUM: 76ff0c531609d1a8576aa0068f91e2ceb2b8bd91
COCOAPODS: 1.3.1
Thanks! Unfortunately, I'm not aware of any reason for this, and I can't reproduce the issue here, so I can't offer much help. Is there another device you can try this on? That would help determine if the issue is device-specific. If not, can you share a sample project that reproduces the issue?
Unfortunately I have only 2 devices for test now. iOS 10.3.3: IPhone 5 (work fine) and iOS 11.2.2: IPhone 6+ (not work).
I will create a new project for reproduce.
I fixed this bug.
I find "Examples" and "pod install" code is different, and "Examples" code can download file correctly,So I change "pod install" code same to "Examples" code, it work.
here is change code on "DBDelegate line:185":
- (void)URLSession:(NSURLSession *)session
downloadTask:(NSURLSessionDownloadTask *)downloadTask
didFinishDownloadingToURL:(NSURL *)location {
DBSessionData *sessionData = [self sessionDataWithSession:session];
NSNumber *taskId = @(downloadTask.taskIdentifier);
DBDownloadResponseBlockStorage responseHandler = sessionData.downloadHandlers[taskId];
NSError *fileError = nil;
NSString *tmpOutputPath = [self moveFileToTempStorage:location fileError:&fileError];
NSURL *tmpOutputUrl = fileError == nil ? [NSURL URLWithString:tmpOutputPath] : nil;
if (responseHandler) {
NSOperationQueue *queueToUse = sessionData.responseHandlerQueues[taskId] ?: [NSOperationQueue mainQueue];
[queueToUse addOperationWithBlock:^{
responseHandler(tmpOutputUrl, downloadTask.response, fileError);
}];
[sessionData.downloadHandlers removeObjectForKey:taskId];
[sessionData.progressHandlers removeObjectForKey:taskId];
[sessionData.progressData removeObjectForKey:taskId];
[sessionData.responsesData removeObjectForKey:taskId];
[sessionData.responseHandlerQueues removeObjectForKey:taskId];
[sessionData.progressHandlerQueues removeObjectForKey:taskId];
} else {
sessionData.completionData[taskId] = [[DBCompletionData alloc] initWithCompletionData:nil
responseMetadata:downloadTask.response
responseError:fileError
urlOutput:tmpOutputUrl];
}
}
- (NSString *)moveFileToTempStorage:(NSURL *)startingLocation fileError:(NSError **)fileError {
NSString *tmpOutputPath = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *tmpDirPath = NSTemporaryDirectory();
BOOL isDir = NO;
BOOL success = YES;
if (![fileManager fileExistsAtPath:tmpDirPath isDirectory:&isDir]) {
success =
[fileManager createDirectoryAtPath:tmpDirPath withIntermediateDirectories:YES attributes:nil error:fileError];
}
if (success) {
tmpOutputPath = [tmpDirPath stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
[fileManager moveItemAtPath:[startingLocation path] toPath:tmpOutputPath error:fileError];
}
return tmpOutputPath;
}
"Examples" code path is :
dropbox-sdk-obj-c-master/Examples/DBRoulette/iOS/CocoaPodsProject/DBRoulette
wish to help you !
More:
If you write pod 'ObjectiveDropboxOfficial'in your Pods Podfile, it install version is 3.0.15,
the download code has the issues.
you should write pod 'ObjectiveDropboxOfficial', '~> 3.4.0' , it will fine.