I'd like to be able to send the viewer to a specific view in the app when they get the push notification, based upon what I send them.
"aps": {
"alert": "look at this stuff",
"view": "wc1"
}
the view 'wc1' is just a tag in a collection view. So what i'd really like to know is, if the user is deep in my app, and they receive a push notification, how do I send them back to the collection view screen.
I've come across the term deep linking, but not been able to find anything on it thus far. Any direction would be really helpful. Thanks!
Try to move your dictionary entry for view outside of the "aps" dictionary.
{
"aps":
{
"alert": "look at this stuff"
}
"view": "wc1"
}
When application is loaded you can detect that in your appdelegate class in that method:
didFinishLaunchingWithOptions
NSDictionary *pushNotification = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(pushNotification )
{
//Handle remote notification
}
If application is still running in background and notification came, you can detect that also in your AppDelegate class:
-(void)application:(UIApplication *)app didReceiveRemoteNotification:(NSDictionary *)userInfo
Related
Is there a delegate method or some way to get the event when a user clears my applications notifications from the Notification drop-down menu? The UIApplication delegate
-(void)application:(UIApplication)application didReceiveLocalNotification:(UILocalNotification *)notification
is only called when they select an event from the list but it isn't called when the list is cleared.
No, if a user clears your notification, it's the same as if it never arrived.
If you clear notification or swipe on notification message this method will be called in appdelegate.m file.
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
//When notification is pressed on background it will enter here
//Get strings based on information on your json payload for example
if([[userInfo objectForKey:#"keyword"] isEqualToString:#"value"]){
//redirect/push a screen here for example
}
I'm able to send push notifications to iOS devices. There is a "Close" button on the notification and a "View" button. When the user hits the "View" button the app opens up to the root view controller. Within the app there is a news section. Let's say the notification is to alert the user that there is a new news story for them to see. If they hit "View", the root view controller will show, instead of the news view controller. How would I go about opening the news view controller? Facebook uses this a lot. Would this be something to change on the server or within the app? Thanks for your help!
For iOS 8+ action button in notifications:
For local notification, appDelegate calls this method when a button on the notification (lock screen or banner) is pressed:
- (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forLocalNotification:(UILocalNotification *)notification
completionHandler:(void (^)())completionHandler
For push notification, appDelegate calls this method when a button on the notification (lock screen or banner) is pressed:
- (void)application:(UIApplication *)application
handleActionWithIdentifier:(NSString *)identifier
forRemoteNotification:(NSDictionary *)userInfo
completionHandler:(void (^)())completionHandler
You have to check the launch options in your application delegate:
application:didFinishLaunchingWithOptions
There you can obtain the payload dictionary of the push notification.
I want to do something like Twitter app: when someone write me I receive the push notification; if I "slide on the notification" the app starts, but not in the normal stream, it starts in a specific view with the tweet that someone wrote me!
In my app I have something like an RSS reader, and the push notification arrives when there is a new news.
So, I want to open the "single news view", and not the main view (that's happening now).
What can I do?
Thanks
You can do two things.
One is to check the launchOptions dictionary of the UIApplicationDelegate method
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
to see if the app was launched via a user clicking on a notification. If so, then in that method you can push the appropriate view controller onto the stack, just as you would normally with in-app usage.
If the app is already open, but in the background then the same theory applies but instead use the UIApplicationDelegate method
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
See this link for information on handling incoming notifications.
Please help me understanding this:
When home button is pressed and iPhone application goes in the background and a Push Notification is received. There is an alert being displayed which contains the message for that notification with "View" button on it. Where this alert is coming from -- IOS generating it?
In my code I wrote code for showing alert when notification comes in inside my
- (void)application:(UIApplication *)iApplication didReceiveRemoteNotification:(NSDictionary *)iUserInfo {
method. And on this alert action I am showing my view controller. Now, I am ending up showing two alerts -- One which is coming from IOS (I believe) and on tap of view is taking me to last visited page of my app and Second which I created and on tap of View is taking me to desired page.
Please help understanding this.
If I understand you correctly, you get two AlertViews instead of one if you click on View. Then you should check whether the application is active or not. Have a look at the UIApplication Class Reference
UIApplication Class Reference #applicationState
- (void)application:(UIApplication *)iApplication didReceiveRemoteNotification:(NSDictionary *)iUserInfo {
if([application applicationState] == UIApplicationStateActive) {
//show alert
}
}
Oliver Drobnik wrote a very detailed examination of the possible message flows when dealing with notifications and app state. The short version - if your apps not frontmost, the OS displays a notification and may launch your app in response to user actions; if your app is frontmost, you're responsible for everything, be it displaying an alert or some other processing.
http://www.drobnik.com/touch/2010/07/understanding-ios-4-backgrounding-and-delegate-messaging/
When the iPhone application is running in background and it receive a remote notification. So it will execute the didReceiveRemoteNotification call back. In that I am going to push to a new UIViewController. But before that its noticed that its calling the applicationWillEnterForeground callback.
In that I am also doing some location update using a modal dialog. So when this notification arrives this both scenarios happens and the app is getting crashed. So is there any way to block the applictiaonWillEnterBackground processing on remote notification. As the moment is little bit hard cos this processing is done after applicationWillEnterBackground controller.
Thank you.
The callback application:didReceiveRemoteNotification: should only be invoked when the application is running in the foreground. When running in the background you should instead get a call to application:didFinishLaunchingWithOptions:.
Since you are asking the question and also using core location it might be that application:didReceiveRemoteNotification: is called when the application is in the background but I would think that would be a bug. At least according to Apple's documentation.
Anyway, NO, you can't block applicationWillEnterForeground:. Without knowing exactly what you are doing in the different callbacks I would recommend that you set a flag in applicationWillEnterForeground: if you are doing something there and then check that flag in application:didReceiveRemoteNotification:
- (void)applicationWillEnterForeground:(UIApplication *)application {
if (somehingHappend) {
somethingHappended = YES;
}
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
if (!somethingHappened) {
// push your view controllers or whatever
}
}
Where somethingHappened is a BOOL defined in the same class as an ivar.