I'm using Parse.com for my iOS application 8 ... In parse database I created a new class called "Relationships", what I'm trying to do is prefix the user of my app to send a friend request to another user. I'm not using PFRelation because I need that friend request is not automatic, but accepted by the user.
In short, the user sends the request richeista of friendship and this remains within the class "Relationship" with the status "Waiting" until the subscriber does not accept the request.
Now I'm able to do everything I can:
- User pointer to register the two (receiver and forwarder's friend request)
- Insert the request status "pending"
My problem is that if my user does not want more 'send the request can not' delete ..
I tried using the ["name of PFObject" deleteInBackground] but I can not delete anything ...
Can you help me figure out how to delete the newly created data from the database to parse?
#pragma mark ADD FRIENDS
-(void)addFriendUserButtonPressed:(UITableViewCell *)customCell {
NSIndexPath *indexPath = [self.tableViewFindUser indexPathForCell:customCell];
PFObject *richiesta = [PFObject objectWithClassName:@"Relation"];
if (!isFiltered) {
PFUser *userFiltered = [self.userArray objectAtIndex:indexPath.row];
if (![self Is_InAttesa:userFiltered]) {
[richiesta setObject:userFiltered forKey:@"To_User"];
[richiesta setObject:[PFUser currentUser] forKey:@"From_User"];
[richiesta setObject:@"Pending" forKey:@"STATUS"];
[richiesta saveInBackground];
} else {
//[richiesta removeObject:[PFUser currentUser] forKey:@"From_User"];
//[richiesta setObject:userFiltered forKey:@"STATUS"];
//[richiesta saveInBackground];
}
}
else {
PFUser *userNotFiltered = [self.userFiltrati objectAtIndex:indexPath.row];
[richiesta setObject:userNotFiltered forKey:@"To_User"];
[richiesta setObject:[PFUser currentUser] forKey:@"From_User"];
[richiesta setObject:@"Pending" forKey:@"STATUS"];
[richiesta saveInBackground];
}
}
This is the Boolean method that I created to recognize (through a query) if users are present in the list of pending friend requests
-(BOOL)Is_InAttesa:(PFUser *)user_inattesa {
for (PFUser *userInAttesa in amiciInAttesaMutableArray) {
if ([[[userInAttesa objectForKey:@"To_User"]objectId] isEqualToString:user_inattesa.objectId]) {
return YES;
}
}
return NO;
}
