Get Data from the APNS Message - ios

Hi I am looking for a way to read the Remote PushNotification without the function
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
The contra of this function is, I have to click on the Notification, then will call this function, but how can I read the Message if I am clicking the App icon from the Homescreen?
Have someone an Idea?
Many Thanks
Greetings
Simon

There's no way to read push notification data when user touched app icon on home screen.

Related

XMPP app terminate and not recive message

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.
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.
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.
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.
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 :)
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.

How to get a notification like the mail app on iOS

My understanding is that both local and remote notification in iOS will not be displayed if the application is in the foreground.
However if I open the mail app on my iPhone and check my email, then on some occasions i get a banner shown to tell me I have received emails. This occurs when the email app is in the foreground.
Does anyone know how this is done (preferably on Swift)? Or is this privilege only available for Apple written applications.
Any help would be appreciated.
You should implement - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo method in your AppDelegate.
If you want to handle them by inflating views or whathaveyou, you need to do it in that particular method.

Is this possible to handle which iOS notification is clicked on the notification centre?

I would like to know, if the user click the notification in the notification centre, whether the application can detect which notification they are clicking and how I can handle it? Thanks.
Yes. In your app delegate, the notification details will be received in the method - (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo
The userInfo will have the payload that you sent with your push notification. It recommended that when you send a push notification that you include identifying information in the payload (such as an object id) to figure out which push notification was selected/received.

iOS push notification won't fire application function

So my problem is that I want to log when the push notification service gets activated for my app. I know for that to happen this function gets called
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)_deviceToken
so I put my logging code in there. However the breakpoints basically state that the program never enters that function. I just recently added the logging code and the device im testing on already has that app activated for push notifications.
Therefore my question is, what can I do, I want to test if my logging code is working or not.
I believe what you are looking for is
- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
This will go in your AppDelegate.m
- (void)unregisterForRemoteNotifications

Local notification handling when application is closed

I have a question related to handling notifications but in case of application is closed. In my iOS application I schedule the local notifications, and I successfully handle them when application is either in foreground or background. But when application is closed and I get local notification I can't handle it. I mean after pressing "show" button I have to move the user to a specific window. But I don't know where to put the part of the code which deals with handling.
Any idea???
Thanks in advance.
Armen
Check - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions in your app delegate, you should receive dictionary from your notification as launching options, as far as I know.
Try this
I could post some code hear but i think the better way is no copy/paste work. So here is the link after they show single notification, they explain how to handle notifications. tutorial about handling notifications

Resources