0

我想知道是否有办法远程写入存储在我的服务器上的 plist 文件。文件所在的目录具有写入权限,但我似乎无法推送新数据。这是我的代码:

NSString *accountURL = [NSString stringWithFormat:@"http://www.mywebsite.com//%@.plist",txtUsername.text];
NSURL *url = [NSURL URLWithString:accountURL];
NSMutableDictionary *account = [[NSMutableDictionary alloc] initWithContentsOfURL:url];

    [account setObject:@"TEST" forKey:@"LastLogin"];
if ([account writeToURL:url atomically:NO]){
NSLog(@"saved");
}else{
NSLog(@"not saved");
}

plist 文件存在是因为我可以毫无问题地从中读取。我只是无法写入文件。

另一方面,如果帐户将存储在我的服务器上,这是否甚至对 AppStore 友好?

4

2 回答 2

2

您需要像这样解析这个 Web 服务,并且需要实现解析器的委托方法。

-(void)startParsingForLoginUser:(NSString*)UserName
{
    NSString *urlString = [NSString stringWithFormat:@"http://www.mywebsite.com//%@.plist",UserName]];
    NSURL *xmlURL = [NSURL URLWithString:urlString];
    NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:xmlURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]autorelease];
    NSURLResponse *returnedResponse = nil;
    NSError *returnedError = nil;
    NSData *itemData  = [NSURLConnection sendSynchronousRequest:request returningResponse:&returnedResponse error:&returnedError];
    xmlParser = [[NSXMLParser alloc] initWithData:itemData];        
    [xmlParser setDelegate:self];
    [xmlParser parse];
}

然后你就可以在服务器上编写 plist 文件了。此外,您还可以使用 POST、PUT 等解析方法,也可以向服务器发送一个SynchronousRequest,这取决于您。

于 2010-12-27T05:39:14.280 回答
1

只读很容易。一旦你开始写东西,你就会获得以下权限:服务器、应用程序、用户。

要解决您的问题,您需要创建一个 Web 服务来验证用户和应用程序、检查权限并保存文件。通常它是一个从你的 iPhone 应用程序接受 POST 或 PUT 的服务器(类似于浏览器为上传所做的)

于 2010-08-26T04:27:37.547 回答