Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 关闭应用程序后如何执行操作?_Ios_Delegates_Performselector - Fatal编程技术网

Ios 关闭应用程序后如何执行操作?

Ios 关闭应用程序后如何执行操作?,ios,delegates,performselector,Ios,Delegates,Performselector,按下“主页”按钮后如何执行操作? 我想我必须给AppDelegate添加一些代码? 是否可以执行以下代码: [self performSelector:@selector(selector)]; 提前谢谢 在appDelegate.m中使用applicationWillResignActive:方法 - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the applicatio

按下“主页”按钮后如何执行操作? 我想我必须给AppDelegate添加一些代码? 是否可以执行以下代码:

[self performSelector:@selector(selector)];

提前谢谢

在appDelegate.m中使用
applicationWillResignActive:
方法

- (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.
}
或者第二个选项是使用
ApplicationIdentinterBackground:

- (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.
}
当然,这取决于你们想做什么。这些评论直接引用了苹果的代码模板


要访问视图控制器的方法,请执行以下操作: 您的错误告诉您,您的应用程序委派类中没有暂停方法。

Swift 3:

func applicationWillResignActive(_ application: UIApplication) {
    // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // 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.
}

为什么要执行选择器?你试过什么?它做错了什么?不是完全相同的问题,但这里的答案应该为您指出正确的方向:感谢您的回答,但我已经尝试过将[自我表演…];在这些AppDelegate语句中编写代码,每次都以错误结束:-2013-11-17 12:34:36.057 Castle[308:60b]-[AppDelegate pause]:发送到实例0x15579a30 2013-11-17 12:34:36.066 Castle[308:60b]的无法识别的选择器***由于未捕获的异常“NSInvalidArgumentException”终止应用程序,原因:'-[AppDelegate pause]:无法识别的选择器发送到实例0x15579a30'----如何添加与viewController.m交互的代码行?谢谢
func applicationWillResignActive(_ application: UIApplication) {
    // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // 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.
}