远程写入 .plist 文件 iPhone SDK

发布于 2024-09-16 05:12:33 字数 582 浏览 6 评论 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 友好?

I am wondering if theres a way to remotely write to a plist file stored on my server. The directory the file is located has write access, but i cannot seem to push the new data. Heres my code:

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");
}

The plist file exists because I can read from it with no problem. I just cannot write to the file.

On another note, is this even AppStore-friendly if the accounts will be stored on my server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑看君怀她人 2024-09-23 05:12:33

您需要像这样解析此 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等解析方法,也可以向服务器发送同步请求,这取决于你。

You need to parse this web service like this and need to implement the delegate methods of parser.

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

And then you would be able to write the plist file on server. Moreover, you could also use the method for parsing like POST, PUT and you can also send aSynchronousRequest to the server, that depends upon you.

吻风 2024-09-23 05:12:33

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

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

Read-only is easy. As soon as you get into writing something you get into permissions for: server, application, user.

To solve your problem you need to create a web service that will authenticate the user and application, check permissions and save the file. Typically it would be a server accepting a POST or PUT from your iPhone app (similar to what browsers do for upload)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文