Question

I have been working on this bug for days and I have no idea what is wrong. Let me outline my design than I will explain the issue. I have two areas where I handle incoming messages, one in a chatviewcontroller and another in the app delegate. My code is such, that if you enter the chat view controller it will handle all messages that are have a custom paramater of "msg". All other messages that have other custom parameters are sent to the app delegate and it handles it. If you dismiss the Chatviewcontroller the app delegate handles all messages.

Here is the issue. If user Z sends message to user X asking to for a friend request, user X will recieve the message if he is currently using the app, regardless if he is in the chat view or the another view. In other words, the message has a custom parameter "newRequest" thus regardless of if user X is in the chatview or not, that message gets handled by the app delegate. This works fine and perfect. However if X has the app in a suspended state, the message gets sent from Z yet never received by X. In the app delegate, when the app is put into a suspended state, it logs the user out with figure 1. When the user returns to the app, the user gets logged back in with Figure 2. Here is another thing to consider, if Z and X have a conversation going (Z sent X a request and X accepted the request (which only works when X has the application in the foreground)) and X sends the application into the suspended state, and Z sends X a message, and X returns, that message does get sent through.

My code that handles the messages is not supplied because it is not a issue. My message handling has break points which aren't activated when Z sends X a request while X has the app in the background than brings it to the foreground. Literally nothing happens.

Figure 1.

-(void)applicationDidEnterBackground:(UIApplication *)application
{
if([[QBChat instance] isLoggedIn])
[[QBChat instance] logout];

}

Figure 2.

if(user&&![[QBChat instance]isLoggedIn]&&pass)
{
//  NSLog(@"%@",[user objectForKey:@"password"]);
//     [[QBChat instance] setDelegate:self];
//     [QBUsers logInWithUserLogin:user.username
//                       password:pass
//                      delegate:self
//                      context:(__bridge void *)((NSString *)user.password)];
    [[QBChat instance] setDelegate:self];
   if([[QBChat instance]loginWithUser:[[DataManager shared]currentUser]])
   {

       NSLog(@"Login Success");


   }
}
Was it helpful?

Solution

So apparently if you do not put a message in the text variable, it does not send. Can someone verify this?

Example: Before

QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = [self.point.chatid integerValue]; // opponent's id
message.text=@"";
message.customParameters=[[NSMutableDictionary alloc]initWithObjectsAndKeys:user.username,@"name",       self.point.className,@"Name",@"newRequest",@"mode",nil];
if([[QBChat instance] sendMessage:message])

After and now works

QBChatMessage *message = [[QBChatMessage alloc] init];
message.recipientID = [self.point.chatid integerValue]; // opponent's id
message.text=@"test";
message.customParameters=[[NSMutableDictionary alloc]initWithObjectsAndKeys:user.username,@"name",    self.point.className,@"Name",@"newRequest",@"mode",nil];
if([[QBChat instance] sendMessage:message])
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top