开发者

How can I know if my apps come from background or are already in foreground

I want to handle APNs differently whether my application come from background or is already in the foreground. Do you know what methods could help 开发者_开发知识库me ?


These are the messages that handle the notification about a changing application state.

– application:didFinishLaunchingWithOptions:
– applicationDidBecomeActive:
– applicationWillResignActive:
– applicationDidEnterBackground:
– applicationWillEnterForeground:
– applicationWillTerminate:
– applicationDidFinishLaunching:

You must implement the one's you need in the designated Delegate! Take a look at the "Task" section of the following link for further assistance, especially the "Monitoring application state changes" part ;-)

Apple's UIApplicationDelegate Protocol Reference


- (void)applicationDidBecomeActive:(UIApplication *)application

It is a method which is executed when app comes to foreground from background. So you can write your code here under the above method about whatever you want to do when app comes to foreground from being in background.


  • (void)applicationWillResignActive:(UIApplication *)application;
  • (void)applicationDidEnterBackground:(UIApplication *)application;
  • (void)applicationWillEnterForeground:(UIApplication *)application;
  • (void)applicationDidBecomeActive:(UIApplication *)application ;

Please have a look at these methods written in delegate.m file


You must implement the application:didReceiveLocalNotification: method. This will be called for both cases. You can differentiate between the cases by checking the applicationState property of [UIApplication sharedApplication]: if it's UIApplicationStateInactive then the app was in background, and if it's UIApplicationStateActive then the app was in foreground.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜