在ios中区分主页按钮点击和来电?

时间:2013-02-07 05:40:56

标签: ios

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

请帮助!!!

2 个答案:

答案 0 :(得分:2)

是的,有点儿。

点击主屏幕按钮或关闭屏幕将导致您的应用程序被置于后台(applicationDidEnterBackground),而电话则不会,并且只会让您的应用程序重新启动其活动状态({{1 }})。

但是,其他操作(如提高多任务栏)也会导致您的应用程序辞职。

答案 1 :(得分: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:.
 */
}

它可以帮助您解决旅游问题。