我已经尝试了一个星期让 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];
}
最佳答案
我从 writeToURL 切换到 writeToFile,使用完全相同的文件路径,它突然工作了。似乎 writeToURL 中可能存在错误。这是在 iOS 7.1 上测试的。
关于ios - Writetourl 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11669622/