如何将内存中的NSDictionary上传到Dropbox,IOS

我有一个xmlstring,我想上传一个.plist到一个保pipe箱文件夹。

目前我创build一个NSDictionary并创build一个临时文件夹,我将该词典编写为该临时文件夹的plist,并将该.plist上传到该临时文件夹中的Dropbox。

我猜这不是一个好的编程解决scheme;

这工作正常

if([title isEqualToString:@"Upload to Dropbox"]) { //pass string in memory to nsdictionary NSData * data = [_uploadPlistString dataUsingEncoding:NSUTF8StringEncoding]; NSString *errorDesc = nil; NSPropertyListFormat format; NSDictionary *uploadFile= (NSDictionary*)[NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc]; //create a temp folder NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"temp"]; NSLog(@"documents datapath: %@",dataPath); //check if folder exist NSError *error = nil; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder //write dictionary to plist NSString *pathTemp = [dataPath stringByAppendingPathComponent:@"agenda.plist"]; // write plist to disk [uploadFile writeToFile:pathTemp atomically:YES]; //get last created file name from singleton SingletonClass *sharedInstance=[SingletonClass sharedInstance]; NSString *destDirectory= sharedInstance.lastCreatedFolderName; //set file name for dropbox NSString *filename = @"agenda.plist"; [[self restClient] uploadFile:filename toPath:destDirectory withParentRev:nil fromPath:pathTemp]; } 

但是,我怎样才能上传内存中的NSDictionary,直接到Dropbox?

没有写它捆绑或类似的东西。

Dropbox SDK的公共API只支持直接从file upload。

但是,由于SDK是开源的,您可以轻松扩展它。

主要上传正在发生

 - (void)uploadFile:(NSString*)filename toPath:(NSString*)path fromPath:(NSString *)sourcePath params:(NSDictionary *)params 

在DBRestClient.m中。

您可以添加一个类别到DBRestClient并添加一个类似的方法来获取NSData而不是文件path。

你可以复制他们大部分的实现,而不是一个文件名你拿一个NSData。 改变Dropbox的文件名生成方式,并用NSData而不是文件实例化NSInputStream。

为了从你的字典中获得一个NSData,你可以使用一个NSKeyedArchiver。