简体   繁体   中英

Device doesn't work, simulator does

What would cause code to execute on the simulator, but not execute properly on the device?

I'm uploading a file to a server via ftp. I'm using http://code.google.com/p/s7ftprequest/ to do the uploading. Is there a simpler way to upload via ftp?

I've tried cleaning targets and resetting everything, but that doesn't help.

//create file for new submission
[submission.text writeToURL:[NSString stringWithFormat:@"%d.txt", submissionNum] atomically:YES encoding:NSUTF8StringEncoding error:nil];

//create new number.txt file
NSString *numberFileString = [NSString stringWithFormat:@"%d",submissionNum];
[numberFileString writeToURL:[NSString stringWithFormat:@"number.txt"] atomically:YES encoding:NSUTF8StringEncoding error:nil];

//connect and upload submission
S7FTPRequest *ftpRequest = [[S7FTPRequest alloc] initWithURL:[NSURL URLWithString:@"ftp://cheekyapps.com/ezhighasiam"]
                                                toUploadFile:[NSString stringWithFormat:@"%d.txt", submissionNum]];

基础常数参考指示260为NSFileReadNoSuchFileError。

Googeling "Cocoa Error 260" let me think, that you are using a path, the device doesn't understand. Maybe with ~ or a path that doesnt work with the sandboxing.

Show some code and we can tell more.

edit

You need to construct a Path to the applications doucument folder in it sandbox. This post might be a start .

in short: To access the Documents folder you should do

edit
This writes your file to the documents folder

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];

NSSting *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", %d.txt]];
[submission.text writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

with the same filePath you can feed your ftp-request

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM