2

我已经尝试了一周让 writeToUrl 工作,但没有......什么都没有。我只是想从 iPhone 应用程序更新我服务器上的文件。这是代码:

NSURL *url = [NSURL URLWithString:@"http://user:pw@192.168.120.167/test.txt"];
NSString *teststring = @"it works";

if ([teststring writeToURL:url atomically:YES encoding:NSASCIIStringEncoding error:nil]) {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Status" message: @"Yessss" delegate: self cancelButtonTitle: @"Close" otherButtonTitles: nil];    
    [alert show];
    [alert release];
}
else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Status" message: @"Noooooo" delegate: self cancelButtonTitle: @"Close" otherButtonTitles: nil];    
    [alert show];
    [alert release];

}
4

2 回答 2

1

我使用完全相同的文件路径从 writeToURL 切换到 writeToFile,然后它突然起作用了。似乎 writeToURL 中可能存在错误。这是在 iOS 7.1 上测试的。

于 2014-07-01T01:30:42.107 回答
0

您只能写入本地文件。请参阅文档

由于目前只支持 file:// URL,所以这个方法和 writeToFile:options:error: 没有区别,除了第一个参数的类型。

于 2013-08-07T15:11:40.500 回答