ios - Writetourl 不起作用

标签 ios objective-c cocoa-touch

我已经尝试了一个星期让 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/

相关文章:

ios - 初始帧 : reuseIdentifier : is deprecated

ios - 从CGImage绘制CGContext

objective-c - 跟踪所有 ObjC 方法调用?

iphone - [UIProgressView setProgress :animated:]: unrecognized selector sent to instance 0x5b34190'

iphone - 通过 Game Center (GameKit) 通过 3G 发送和接收数据停止工作

ios - UIDocumentInteractionController 不工作

objective-c - 有人可以解释 Objective-C 中的函数名称吗?

iOS 如何将键盘与文本字段结合起来并一起显示?

ios - 结合 Grapheme Joiner 在 Cocoa、iOS 中不起作用?

iphone - 非 3G iPhone 的三角 GPS 准确度如何?