xmpp doesn't disconnect while terminate application?
b'cas need enable apns once application terminated user same whatsapp work.
if close app within 2 min while connecting xmpp server, apns enable quickly. if close application after 5-6 min apns doesn't enable quickly. may take 1-2 min or time more. in case of 5-6 min, if lock device apns enable quickly.
i have use below code push configuration , disconnect xmpp.
-(void)configurepushnotifications { nsstring *jabberid = [nsstring stringwithformat:@"test123"]; nsxmlelement *iq = [nsxmlelement elementwithname:@"iq"]; [iq addattributewithname:@"type" stringvalue:@"set"]; [iq addattributewithname:@"id" stringvalue:strdevicetoken]; nsxmlelement *push = [nsxmlelement elementwithname:@"push" xmlns:@"p1:push"]; nsxmlelement *ping = [nsxmlelement elementwithname:@"ping" xmlns:@"urn:xmpp:ping"]; nsxmlelement *keepalive = [nsxmlelement elementwithname:@"keepalive"]; [keepalive addattributewithname:@"max" integervalue:60]; nsxmlelement *session = [nsxmlelement elementwithname:@"session"]; [session addattributewithname:@"duration" integervalue:60]; nsxmlelement *body = [nsxmlelement elementwithname:@"body"]; [body addattributewithname:@"send" stringvalue:@"all"]; [body addattributewithname:@"groupchat" stringvalue:@"true"]; [body addattributewithname:@"from" stringvalue:@"username"]; nsxmlelement *status = [nsxmlelement elementwithname:@"status"]; [status addattributewithname:@"type" stringvalue:@"xa"]; [status setstringvalue:[nsstring stringwithformat:@"new message %@",jabberid]]; nsxmlelement *offline = [nsxmlelement elementwithname:@"offline" stringvalue:@"true"]; [push addchild:keepalive]; [push addchild:session]; [push addchild:body]; [push addchild:status]; [push addchild:offline]; nsxmlelement *notification = [nsxmlelement elementwithname:@"notification"]; [notification addchild:[nsxmlelement elementwithname:@"type" stringvalue:@"applepush"]]; [notification addchild:[nsxmlelement elementwithname:@"id" stringvalue:strdevicetoken]]; [push addchild:notification]; nsxmlelement *appid = [nsxmlelement elementwithname:@"appid" stringvalue:@"com.test.test"]; [push addchild:appid]; [iq addchild:ping]; [iq addchild:push]; [[self xmppstream] sendelement:iq]; } - (void)gooffline { xmpppresence *presence = [xmpppresence presencewithtype:@"unavailable"]; [[self xmppstream] sendelement:presence]; } - (void)goonline { xmpppresence *presence = [xmpppresence presence]; // type="available" implicit nsstring *domain = [xmppstream.myjid domain]; //google set presence priority 24, same compatible. if([domain isequaltostring:@"gmail.com"] || [domain isequaltostring:@"gtalk.com"] || [domain isequaltostring:@"talk.google.com"]) { nsxmlelement *priority = [nsxmlelement elementwithname:@"priority" stringvalue:@"24"]; [presence addchild:priority]; } [[self xmppstream] sendelement:presence]; } - (void)applicationwillterminate:(uiapplication *)application { application.applicationiconbadgenumber = 0; } - (void)applicationdidenterbackground:(uiapplication *)application { // use method release shared resources, save user data, invalidate timers, , store enough application state information restore application current state in case terminated later. [self gooffline]; } - (void)applicationdidbecomeactive:(uiapplication *)application { [self goonline]; // restart tasks paused (or not yet started) while application inactive. if application in background, optionally refresh user interface. }
can me?
Comments
Post a Comment