我在網上看到了一些關於如何使用解析或用戶之間的聊天進行私人消息傳遞的教程,但它們都很複雜,很難適合我項目加上大多數是聊天室而不是私人消息。使用Parse API在兩個用戶之間進行聊天的最簡單的方法
我想要做的是找到兩個用戶之間進行聊天的最簡單方法。 我的代碼很簡單,我有一個文本框和一個按鈕,我們假設一個userOne
發送這些數字:1234
。
然後userTwo
把同樣的數字在文本字段,並按下按鈕將其發送到parse.com
,然後我有一個查詢尋找它,看看是否有用戶之間的匹配。
一旦匹配,我想問他們兩個用戶是否想聊天,如果是,所以他們可以互相聊天。
現在,我想從你知道的所有優點(:-D)我有哪些選擇,
我想到了通知系統用戶之間(它甚至有可能?)或者可能(因爲聊天室)創建一個UILabel
,其中NSTimer
代碼將每隔2秒更新一次,另一個文本字段用戶可以相互發送文本。
我的另一個問題是,一旦我找到第二個用戶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
}
任何幫助,將不勝感激!謝謝你們 。
您也遺漏了一半的代碼。請你填寫它。並儘量保持格式良好:D – Fogmeister
嘿,我沒有遺漏一半的代碼,這是我查詢的整個代碼。我不知道的是如何保存用戶ID並在以後使用它,以及我仍然困惑如何在他們兩個用戶之間創建聊天室。謝謝你回覆壽。 – XcodeNOOB