目标C-如何通过提供路径从iphone上传文件

时间:2014-04-02 12:39:53

标签: iphone objective-c cocoa-touch cordova dropbox-api

我的代码使用dropbox插件将文件从我的应用程序上传到Dropbox。下面的代码在模拟器中运行,但是当我运行它时路径会有所不同。我如何访问iphone路径?

-(void) upload:(CDVInvokedUrlCommand*)command
{

CDVPluginResult* pluginResult = nil;

NSString* javaScript = nil;

NSLog(@"Dropbox backup method is executing");

NSString *str=[command.arguments objectAtIndex:0];

NSLog(@"file:%@",str);

NSArray *paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,      NSUserDomainMask, YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *destDir = @"/";

[[self restClient] uploadFile:str toPath:destDir withParentRev:nil fromPath:    

[documentsDirectory stringByAppendingString:str]];

pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];

javaScript = [pluginResult toSuccessCallbackString:command.callbackId];

[self writeJavascript:javaScript];
}

有人可以告诉我如何访问iPhone的路径吗?

2 个答案:

答案 0 :(得分:0)

试试这段代码

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *yourPath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"%@",str];

答案 1 :(得分:0)

NSString * bundle = [[NSBundle mainBundle] bundlePath];

使用此代码,我们可以获取设备中文件的路径。