send push notification to ios for chat to offline user, openfire xmpp send push notification to ios for chat to offline user, openfire xmpp ios ios

send push notification to ios for chat to offline user, openfire xmpp


XMPP requires a persistent socket connection or a "persistent" BOSH connection during your whole XMPP session. I think your challenge is that iOS does not allow you to run your app and socket in background. Whenever your iOS app goes in background iOS kills your socket connection, and your Openfire server kills your XMPP session. This means the user goes offline. Which is also the reason why incoming messages for this user go to the offline storage.

Sorry for this response, but all 3 solutions you suggested are terrible hacks ;-). If you want to come up with a good solution you have to go very deep into XMPP and iOS. 1 week is a very short timeframe for this.

Can anyone tell how Whatsapp and other popular apps handle this?

They keep the XMPP session alive. This works only with highly modified XMPP servers, some "XMPP Client Proxy" in between which keeps your session running while your app is in background, or a combination or both.


I have a solution for you.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.ary_UserStatus = [NSMutableArray array];    NSMutableArray *ary_TempFromUserDefaults = [NSMutableArray array];    ary_TempFromUserDefaults = [[NSUserDefaults standardUserDefaults] valueForKey:@"KejdoUserStatus"];    if ([ary_TempFromUserDefaults count]>0)    {         self.ary_UserStatus = [[NSUserDefaults standardUserDefaults]    valueForKey:@"KejdoUserStatus"];       }      self.df_UserStatus = [[NSDateFormatter alloc] init];      [self.df_UserStatus setDateFormat: @"hh:mm a MM/dd/yyyy"];}- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence{    DDLogVerbose(@"%@: %@ - %@", THIS_FILE, THIS_METHOD, [presence fromStr]);    NSString *str_UserName = [[presence from] user];    NSString *str_LastSeenDate = [self.df_UserStatus stringFromDate:[NSDate date]];    NSMutableDictionary *mdic_UserPresence = [[NSMutableDictionary alloc] init];    [mdic_UserPresence setValue:str_UserName forKey:@"Name"];    [mdic_UserPresence setValue:str_LastSeenDate forKey:@"Date"];    [mdic_UserPresence setValue:[presence type] forKey:@"Type"];    if ([self.ary_UserStatus count]>0)    {        int index;        BOOL IS_exist=FALSE;        for (int i=0; i<[self.ary_UserStatus count]; i++)        {            NSString *str_UserFromArray = [[self.ary_UserStatus objectAtIndex:i] valueForKey:@"Name"];            if ([str_UserName isEqualToString:str_UserFromArray])            {                IS_exist = TRUE;                index = i;                [[NSUserDefaults standardUserDefaults] setObject:str_UserName forKey:@"Status"];            }            else            {            }        }        if (IS_exist) {            [self.ary_UserStatus replaceObjectAtIndex:index withObject:mdic_UserPresence];        }        else        {            [self.ary_UserStatus addObject:mdic_UserPresence];        }    }    else    {        [self.ary_UserStatus addObject:mdic_UserPresence];    }    [[NSUserDefaults standardUserDefaults] setObject:self.ary_UserStatus forKey:@"KejdoUserStatus"];    [[NSUserDefaults standardUserDefaults] synchronize];    [[NSNotificationCenter defaultCenter] postNotificationName:@"UserStatusChangeNotification" object:self];}

And wherever you are sending message to other user in chat. Do this

 if(appDelegate.ary_UserStatus.count>0)    {     for (int i=0; i<[appDelegate.ary_UserStatus count]; i++)     {      if ([jid.user isEqualToString:[NSString stringWithFormat:@"%@",[[appDelegate.ary_UserStatus objectAtIndex:i] valueForKey:@"Name"]]])        {         if ([[[appDelegate.ary_UserStatus objectAtIndex:i] valueForKey:@"Type"] isEqualToString:@"available"])           {                                // Do something like table reload.                                break;             }               else                    [self sendPushNotification];           }         }       }        else            [self sendPushNotification];