I am working in XMPP Application. When I terminate and kill My Application than,
1)User is Not Connected In XMPP Server. User is Offline. But I want User is Connected and Online. Like Whats App(Appliction).
2)I can't get Any Messages From XMPP Server Side at that time,
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
This method is not call. So, How Can I get Messages ?
And i also implement Pushnotification but in this way same issue Like,When app is Kill and Terminate than,This method is not call,
- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
So, Please Guide me In Proper Way and Suggest me How to work as like same Whats App(Application).
Also, We can't set VOIP Flag In .plist file Because this way is not Proper and reject by the apple.
My Goal is Only Notification Work As like Whats App.
5 Answers
Answers 1
1)User is Not Connected In XMPP Server. User is Offline. But I want User is Connected and Online. Like Whats App(Appliction).
Once you closed or minimized WhatsApp the user gets offline (tested on iPhone4s), and messages received in this state are as push notifications.
2)I can't get Any Messages From XMPP Server Side at that time,
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
This method get called only when application is active. So you can not get messages here after you killed your application.
- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler
This method will get called in following scenarios
- If your app is active and you got any new push notification.
- If your app is in background or killed or not started then system will show only notification on the top bar, once user tapped on notification it will open your application and then the method will get called.
And of course you can not use VOIP.
WhatsApp shows custom notification when user is active in WhatsApp. You need to send push notification for every message of your conversation. In this case
- If user is active then show your custom notification in app.
- If user is inactive (i.e. killed or minimized app) then system will show Notification in notification center.
When user taps on notification, system will launch application, and you have to check for app launching conditions (from which source app launched) and according to conditions join server/chat (or groups if you are using group chat).
Once you joined server with your name/nickname, you will get recent chats. You can also get history, you need to specify while joining chat server / group.
Make sure you are disconnecting from server and also from group when your app is getting minimized or killed. Use following methods to disconnect and/or related changes
1. - (void)applicationDidEnterBackground:(UIApplication *)application 2. - (void)applicationWillTerminate:(UIApplication *)application
Hope this will help you, I have implemented same to achieve expected results as WhatsApp.
Answers 2
First of all, If your application is terminated then you will receive Push Notification
data in
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
in launchOptions
dictionary with key
if (launchOptions) { if ([launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) { // Your code } }
Second, you can use background fetch for retrieving user's message, While background fetch you can connect your stream and fetch messages from XMPP server.
NOTE: WhatsApp's (iOS) version, fetches the message as soon as you open the app, it is connecting to the stream and then fetches the messages.
However you can implement your own logic to customize your functionality.
Answers 3
When your app kill, that time XMPP Deactivate all service.So, you can send webservice to server which can tell - you are offline.
Then after sever can send you Push notification all chat content.
Answers 4
Read the following document it will help you. http://xmpp.org/extensions/xep-0168.html
We ned to add priority when the presence of user is set as below:
-(void)GoOnline{ XMPPPresence *goOnline = [XMPPPresence presence]; NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"-1"]; [goOnline addChild:priority]; [xmppStream sendElement:goOnline]; }
Now to know more about priority, it's role and how it works, read the document from above link.
Hope it may help you :)
Answers 5
Check this link and read the Remote Notifications (iOS 7 and Greater)
section which is combining the Background Modes and Remote notifications
to download content before launching the app.
You will get the idea and you can implement in your preferred language obj-c or swift.
0 comments:
Post a Comment