我在网上看到了一些教程,如何通过解析或用户之间的聊天进行私人消息传递,但它们都很复杂,很难将其融入我的项目,而且其中大多数是聊天室而不是私人消息传递。
我要做的是找到在两个用户之间进行聊天的最简单方法。我的代码有点简单,我有一个文本字段和一个按钮,比如说userOne
发送这些数字:1234
。
然后userTwo
在文本字段中输入相同的数字并按下按钮将其发送到parse.com
,然后我有一个查询来查找它并查看用户之间是否存在匹配。
一旦匹配,我想问他们两个用户是否想聊天,如果是,那么他们可以互相聊天。
现在,我想从各位专业人士那里知道(:-D)我的选择是什么,
我考虑过用户之间的通知系统(甚至可能吗?)或者(因为创建聊天室很复杂)创建一个每 2 秒更新一次UILabel
的NSTimer
代码和另一个用户可以相互发送文本的文本字段。
我的另一个问题是,一旦我找到第二个用户 ID,我该如何保存它并以备后用?
我需要将它保存到 NSString 吗?
无论如何,这是我的查询代码(当您按下按钮发送到号码时)
PFObject *addValues= [PFObject objectWithClassName:@"someNumber"];
[addValues setObject:someNumbers forKey:@"numbers"];
[addValues setObject:whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];
PFQuery* numQuery = [PFQuery queryWithClassName:@"someNumber"];
[numQuery whereKey:@"numbers" equalTo:someNumbers];
[numQuery whereKey:@"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if(!error) {
//alert view for thanking the user for sending a message
UIAlertView *messageForSending = [[UIAlertView alloc]initWithTitle:@"thank you"
message:@"the details has been send"
delegate:nil
cancelButtonTitle:@"okay"
otherButtonTitles:nil];
[messageForSending show];
for(PFObject *numObject in objects) {
// the numbers if found are right here
if (objects.count > 1 ) {
NSLog(@"yay we found %lu objects", (unsigned long)objects.count);
// Here I can see what is the ID of the second user I want to create chat with
NSLog(@" the numobject is %@ " , numObject);
} else {
NSLog(@"there is no match ");
// showing later UIAlert that there is no match
}
任何帮助,将不胜感激 !谢谢你们 。