0

i'm losing my head over this one just can't figure it out .

my app has a text field and a button which you can submit your phone number or just a number ( it doesn't matter ) .

the button method is this

PFObject *addValues= [PFObject objectWithClassName:@"phoneNumber"];
[addValues setObject:phoneNumbers forKey:@"numbers"];
[addValues setObject:whoIsTheUser forKey:@"theUser"];
[addValues saveInBackground];

then i add another button which check if a different user put in the box the same number the first user did, so i'm running a query for this , the code right here :

PFQuery* numQuery = [PFQuery queryWithClassName:@"phoneNumber"];
[numQuery whereKey:@"numbers" equalTo:phoneNumbers];
[numQuery whereKey:@"theUser" notEqualTo:[PFUser currentUser]];
[numQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){


    if(!error)
    {
       // send an alert view for data-has-been-sent 

        UIAlertView *messageForSending = [[UIAlertView alloc]initWithTitle:@"thank you" message:@"the details has been send" delegate:nil cancelButtonTitle:@"okay" otherButtonTitles:nil, nil ];
        [messageForSending show];


        for(PFObject *numObject in objects) {

            // checking how much objects did the query find ...

            if (objects.count > 1 ) {


                NSLog(@"yay we found %lu objects", (unsigned long)objects.count);

                // in the future i will handle those multiply objects somehow :D

            }else{

                // if there's 1 results i know it's going to show this message

             **// HOW CAN I CHECK WHAT'S THE OTHER PFUser ID IS ? AND HOW CAN I MAKE RELATIONSHIP WITH THE CURRENT PFUser ??**

                NSLog(@"yup there is a match");
                //NSLog(@"checking objects %lu", objects.count);
                NSLog(@" object names %@", objects);
                // showing alert message for success

                UIAlertView *successMessage = [[UIAlertView alloc]initWithTitle:@"THERE IS A           MATCH" message:@" we found a match, would u like to talk with him ?" delegate:nil            cancelButtonTitle:@"cancel" otherButtonTitles:@"yes", nil];
                [successMessage show];










            }



        }

    }
    else
    {
  // there's an error so i will show here in the future an UIAleart view for trying again.

        NSLog(@" big error !!!");

    }
}


 ];

so supposed there is 1 match, and both users put the same number ( you can see in the code above i put ** for my question ) . how can I create a Relationship code with the Current PFUser and the new User I found in the Objects ? I want to create a relationship between them two users ID and put it on the database of parse as Friends class. BTW. the code above is working , I created two users and typed 1234 for both of them and it's work :D - now all i got left is connect them both users .

thank's a lot guys ! .

esqew
  • 42,425
  • 27
  • 92
  • 132
XcodeNOOB
  • 2,135
  • 4
  • 23
  • 29

1 Answers1

0

In your second button query, add this line:

[numQuery includeKey:theUser];

This will ensure the user object is fetched together with the result. You can then get this user object with:

PFUser *otherUser = [objects lastObject]; // Assuming there was only 1 user in the result

Now you have both users.

Then, to relate them, you need either a column on each user object with an array of other users who are friends, and update each of these columns on both user objects with the user object of the other user. This column should be an array of pointers.

However, a better approach is to use a separate parse class for friends linking. I assume people can have several such friendships. Maybe that's what your Friends class is for?

Marius Waldal
  • 9,537
  • 4
  • 30
  • 44
  • thank you for answering so quick, i did as you said and save it like this : PFUser *otherUser = [objects lastObject]; PFObject *newChat = [PFObject objectWithClassName:@"NewChat"]; [newChat setObject:whoIsTheUser forKey:@"sender"]; [newChat setObject:otherUser forKey:@"reciever"]; [newChat saveInBackground]; now i have a NEW class with the USERS. now let's say I have another class with text that user upload , how can i get the other user to see it ? thank you for any help ! :D – XcodeNOOB Mar 19 '14 at 23:57
  • Creating a chat app can be "easy" or tricky, depending on the level of sophistication you want. There are a couple of frameworks out there you can use so you don't have to invent it all yourself. If you DO want to give it a try, have a look at this tutorial (which even uses Parse): http://attila.tumblr.com/post/21180235691/ios-tutorial-creating-a-chat-room-using-parse-com -- There is also a chatDemo on github that uses parse, but it is fairly old now: https://github.com/dmendels/chatDemo – Marius Waldal Mar 20 '14 at 07:25
  • yup i found this tutorial on google :-) , I try to play with it but havn't figure out how to make it a Private Chat between User A to User B . this chat is kind of global , is it possible to make it private between two users ?? – XcodeNOOB Mar 20 '14 at 16:08
  • Not entirely sure what you put in the term "private" here, but that is kind of a broad question. You can use the ACL to restrict who can see a chat or you can implement some kind of check on who can join a chat. There should be many solutions to this. – Marius Waldal Mar 20 '14 at 18:01