我有一个要作为 .plist 上传到保管箱文件夹的 xml 字符串。
目前我创建一个 NSDictionary 并创建一个临时文件夹,我将字典作为 plist 写入该临时文件夹,并将该临时文件夹中的 .plist 上传到保管箱。
我猜这不是一个好的编程解决方案;
这工作正常
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?
无需将其写入捆绑软件或类似的东西。