【问题标题】:Device doesn't work, simulator does设备不工作,模拟器可以
【发布时间】:2011-06-20 06:19:21
【问题描述】:

什么会导致代码在模拟器上执行,但在设备上无法正常执行?

我正在通过 ftp 将文件上传到服务器。我正在使用http://code.google.com/p/s7ftprequest/ 进行上传。有没有更简单的通过 ftp 上传的方法?

我已尝试清理目标并重置所有内容,但这无济于事。

//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]];

【问题讨论】:

标签: objective-c ios upload ftp ios-simulator


【解决方案1】:

Foundations Constants Reference 表示 260 是 NSFileReadNoSuchFileError。

【讨论】:

    【解决方案2】:

    Googeling "Cocoa Error 260" 让我想想,你使用的是路径,设备不理解。可能使用 ~ 或一条不适用于沙盒的路径。

    显示一些代码,我们可以了解更多。

    编辑

    您需要在沙箱中构建应用程序文档文件夹的路径。 This post might be a start.

    简而言之:要访问 Documents 文件夹,您应该这样做

    编辑
    这会将您的文件写入文档文件夹

    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];
    

    使用相同的文件路径,您可以提供您的 ftp 请求

    【讨论】:

    • 我刚刚发布了我认为导致问题的原因。它正在创建两个文件,然后上传它们
    • 我不确定。当您以编程方式创建文件时,它们就是保存到的位置。我还是 Obj-C 的新手
    • 在这种情况下,请确认您没有写入包(将其视为应用程序的包)。这会破坏配置。
    • 将所有内容保存到 Documents 文件夹或类似文件夹中。并使用“NSSearchPathForDirectoriesInDomains”构建路径
    • 取决于你所在的时区:去街上拥抱你看到的下一个人。可能是我。坏主意,如果是晚上......
    猜你喜欢
    • 2017-06-08
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2023-03-23
    相关资源
    最近更新 更多