2

是否有任何解决方案可以区分手动退出应用程序(通过主页按钮单击)和通过来电退出应用程序?

请帮忙!!!

4

2 回答 2

2

是的,有点。

单击主页按钮或关闭屏幕将导致您的应用程序进入后台(applicationDidEnterBackground),而电话不会,只会让您的应用程序退出其活动状态(applicationWillResignActive)。

但是,其他操作(例如提升多任务栏)也会导致您的应用程序退出。

于 2013-02-07T05:48:22.597 回答
0

您无法处理主页按钮单击。但是,当用户单击主页按钮或点击应用程序图标时,应用程序的委托方法会被调用。您可以在其中编写代码。

- (void)applicationWillResignActive:(UIApplication *)application
{
   /* Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
 Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
 */
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
/*
 Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
 If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
 */
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
/*
 Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
 */
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
 Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
 */
}

- (void)applicationWillTerminate:(UIApplication *)application
{
/*
 Called when the application is about to terminate.
 Save data if appropriate.
 See also applicationDidEnterBackground:.
 */
}

愿它帮助您解决旅游问题。

于 2013-02-07T05:53:38.473 回答