[英]Write NSDictionary to ONLINE .plist. Is it possible?
I'm writing an app for instant messaging aaand I'm stuck. 我正在编写一个用于即时通讯的应用程序,但遇到了麻烦。
I am able to read data (dictionary) from plist that's on my dropbox, but I can't modify it from my app, what is a thing I actually want to achieve. 我可以从我的保管箱上的plist读取数据(字典),但是我无法从我的应用程序修改它,这实际上是我想要实现的目标。
Here is how I read the online .plist file: 这是我阅读在线.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.
And this is how I am trying to save it if I change it 这就是我尝试保存它的方式
- (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];
}
}
If I do it locally/offline (in some folder inside my Mac or app directory) using writeToFile:
it works. 如果我使用
writeToFile:
在本地/离线(在Mac或应用程序目录中的某个文件夹中)执行此操作, writeToFile:
它将起作用。 When I use writeToURL:
it doesn't work. 当我使用
writeToURL:
它不起作用。
My questions are: 我的问题是:
Thanks! 谢谢!
Instant messaging applications are almost always best done using sockets
. 即时消息应用程序几乎总是最好使用
sockets
来完成。 I'd HIGHLY recommend against using a file on a server to read and write from. 我强烈建议您不要使用服务器上的文件进行读写。 While it's possible, you're asking for a world of pain and slugish-ness.
尽管有可能,但您正在寻求一个痛苦与迟钝的世界。
So to answer your questions in a striaght forward manner: 因此,请以直截了当的方式回答您的问题:
node.js
here: http://socket.io/get-started/chat/ node.js
聊天服务器示例: http : node.js
Let me know if you have any questions. 如果您有任何疑问,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.