Hi there i would like to know which app delegate method get called when my app launch from a push notification (When the app was previously in the background ?)
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
Also check this answer.
Implement the didReceiveLocalNotification: method in your AppDelegate.
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)notif {
// Handle the notification here
}
Check the documentation of UIApplicationDelegate
Related
I send 10 messages in row to APNS.When application is in background, I receive all of them.
But when Application is in foreground I recieve 8 notifications.
What can be a problem here?
Here is my code which is extremely simple:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
NSLog(#"Test push...");
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeSound|UIRemoteNotificationTypeNone)];
[self checkForRegisteredUser];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
return YES;
}
Not sure will this is what you're looking for,
Here is how push notification works,
So when you application is on background, you application will never receive the push notification from the APNs but it will come to your notification tray with the message as they sent it from the server.
But if your application is in the foreground. the method in you app delegate
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
will receive the notification and will perform the necessary action as you have defined in it.
In case if you did not receive the notification you need to check the network connection.
I have developed a similar application like yours and its works well as you are expecting..
Hi I have an app on the App Store which used to receive Push Notifications perfectly but after a recent update it seems to have stopped.
I have not changed any of the notification code so I was wandering if there have been any changes in iOS 5.1 which may be causing the issue.
Anyone had a similar experience and know how to fix it?
In the application delegate I am registering for notifications:
[[UIApplication sharedApplication]
registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound)];
and implementing the following methods:
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)devToken
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
I have implemented push notification service in iphone device, but running app will not get the notification service alert message, how to handle the APN service in running app.
Thanks in advance
Just implement in your application delegate
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
and you'll be happy =)
Implement the following code in the delegate method:
(void)application:(UIApplication *)application
didReceiveLocalNotification:(UILocalNotification *)notification
{
application.applicationIconBadgeNumber = 0;
NSString *reminderText = [notification.userInfo objectForKey:kRemindMeNotificationDataKey];
}
Also follow the link. It must help you.
http://useyourloaf.com/blog/2010/7/31/adding-local-notifications-with-ios-4.html
I already use the:
(void)applicationDidEnterBackground:(UIApplication *)application {}
method, but I can't differentiate if is because press the home button or the on/off button.
Thanks in advance,
For the on/off button(or an incoming call or SMS):
- (void)applicationWillResignActive:(UIApplication *)application
For the Home button:
- (void)applicationDidEnterBackground:(UIApplication *)application
With the notification of applicationWillResignActive, applicationDidBecomeActive will still enter while you are entering in background. But there is a way to differentiate by getting the state of the app, so try this in applicationDidEnterBackground.
- (void)appHasGoneInBackground {
bool inBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground;
// lockScreen state
if (!inBackground) {
// do something
}
}
Apple's UIApplication-class reference
Use - (void)applicationDidEnterBackground:(UIApplication *)application {} when your app is entering the background (home button) and - (void)applicationWillTerminate:(UIApplication *)application when it's about to be closed (on/off button or iOS call to close after a random time in background).
My understanding is that when you lock or unlock your iOS device your application delegate will call - (void)applicationWillResignActive:(UIApplication *)application and - (void)applicationDidBecomeActive:(UIApplication *)application, respectively. Locking and unlocking are similar to receiving an interruption like a phone call. Sending your application to the background by hitting the home button calls different methods, namely - (void)applicationDidEnterBackground:(UIApplication *)application and - (void)applicationWillEnterForeground:(UIApplication *)application.
I am using LocalNotification in my app. It is working fine but once ApplicationIconBadgeNumber is set, not able to remove it from App. How to remove it?
You need to set the application applicationIconBadgeNumber.
For example in the application didReceiveLocalNotification.
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notif {
application.applicationIconBadgeNumber = notif.applicationIconBadgeNumber-1;
}