将 NSDictionary 写入 ONLINE .plist。可能吗?

Write NSDictionary to ONLINE .plist. Is it possible?

我正在编写一个用于即时消息传递的应用程序,但我被卡住了。

我可以从我的保管箱上的 plist 中读取数据(字典),但我无法从我的应用程序中修改它,这是我真正想要实现的目标。

以下是我阅读在线 .plist 文件的方式:

@Implementation
NSDictionary *wholePlist;
-(void)viewDidLoad
{
     wholePlist = [[NSDictionary alloc]initWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://dl.dropboxusercontent.com/s/cfpree9see19t00/users.plist"]]];

     self.allUsers = [wholePlist objectForKey:@"allUsers"];
} //self.allUsers is NSDictionary, also.

如果我更改它,这就是我试图保存它的方式

- (IBAction)registerButtonPressed:(UIButton *)sender {

    NSString *username = self.usernameTextField.text;
    NSString *password = self.setPassTextField.text;
    NSMutableArray *myContacts = [[NSMutableArray alloc]init];
    NSMutableArray *inbox = [[NSMutableArray alloc]init];

    NSDictionary *user = [[NSDictionary alloc]initWithObjects:@[username, password, myContacts, inbox] forKeys:@[@"username",@"pass",@"myContacts",@"inbox"]];

    if ([user isEqualToDictionary:[self.allUsers objectForKey:username]]) {
        [[[UIAlertView alloc]initWithTitle:@"Registration error" message:@"Username already taken. Please, choose another username." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil]show];
    } else {
        NSURL *plistURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://dl.dropboxusercontent.com/s/cfpree9see19t00/users.plist"]];
        [self.allUsers setValue:user forKey:username];
        [self.allUsers writeToURL:plistURL atomically:YES];
    }
}

如果我使用 locally/offline(在我的 Mac 或应用程序目录中的某个文件夹中)使用 writeToFile: 它可以工作。当我使用 writeToURL: 时它不起作用。

我的问题是:

  1. 这有可能吗,我想达到什么目的?
  2. 是否可以使用任何其他存储客户端?
  3. 如果可以使用其他存储客户端,请给我来源 link 如何或解释如何。

谢谢!

即时通讯应用程序几乎总是最好使用 sockets。我强烈 建议不要使用服务器上的文件进行读写。虽然这是可能的,但你要求的是一个痛苦和迟钝的世界。

所以直接回答你的问题:

  1. 是的...不要这样做。
  2. 是的。当然,您可以使用 CloudKit 数据库或文件上传部分。同样,我建议不要使用这种方法,因为它速度慢且网络开销高。
  3. 我强烈建议阅读套接字:http://en.wikipedia.org/wiki/Network_socket to better understand this approach. I have a chat socket written in C++. However it does a bit more than what you may need: https://github.com/theMonster/ModularServer. Also, there's a very popular chat server example for node.js here: http://socket.io/get-started/chat/

如果您有任何问题,请告诉我。