tomar profesionales plus fotos diseño desde con como arriba iphone uiviewcontroller multitasking background-foreground

diseño - como tomar fotos profesionales con iphone 7 plus



Uso de métodos de fondo/primer plano en AppDelegate (2)

Cada objeto recibe una notificación UIApplicationDidEnterBackgroundNotification cuando la aplicación entra en segundo plano. Entonces, para ejecutar un código cuando la aplicación está en segundo plano, solo tiene que escuchar esa notificación donde desee:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appHasGoneInBackground:) name:UIApplicationDidEnterBackgroundNotification object:nil];

No olvides liberar al oyente cuando ya no necesites escucharlo:

[[NSNotificationCenter defaultCenter] removeObserver:self];

Y lo mejor de lo mejor, puedes jugar de la misma manera con las siguientes notificaciones:

  • UIApplicationDidEnterBackgroundNotification
  • UIApplicationWillEnterForegroundNotification
  • UIApplicationWillResignActiveNotification
  • UIApplicationDidBecomeActiveNotification

Estoy planeando implementar tareas múltiples en mi aplicación. Aquí puedo ver muchos métodos para hacerlo en AppDelegate como applicationWillResignActive , applicationDidEnterBackground , applicationWillEnterForeground , ...

Pero ... No veo la forma en que deberían usarse, ni por qué no están en ViewControllers ... Ni para qué están aquí.

Quiero decir: cuando la aplicación ingresa en segundo plano, no sé en qué vista está mi usuario. Y, de regreso, cuando la aplicación entra en primer plano, ¿cómo sabría qué hacer y qué llamar para actualizar la vista, por ejemplo?

Hubiera entendido si esos métodos en cada controlador de vista, pero aquí, no veo para qué se pueden utilizar de una manera concreta ...

¿Puede ayudarme a comprender la manera de implementar cosas en esos métodos?


No están en ninguno de los controladores de visualización porque iOS adopta un patrón de diseño de "delegado", donde puede estar seguro de que un método se activará en una clase (en este caso, el delegado de aplicación para su aplicación) cuando sea necesario.

Como proceso de aprendizaje, ¿por qué no pones NSLog en esos métodos para ver cuándo los despiden?

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. NSLog(@"didFinishLaunchingWithOptions"); [self.window makeKeyAndVisible]; return YES; } - (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. */ NSLog(@"applicationWillResignActive"); } - (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, called instead of applicationWillTerminate: when the user quits. */ NSLog(@"applicationDidEnterBackground"); } - (void)applicationWillEnterForeground:(UIApplication *)application { /* Called as part of transition from the background to the active state: here you can undo many of the changes made on entering the background. */ NSLog(@"applicationWillEnterForeground"); } - (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. */ NSLog(@"applicationDidBecomeActive"); } - (void)applicationWillTerminate:(UIApplication *)application { /* Called when the application is about to terminate. See also applicationDidEnterBackground:. */ NSLog(@"applicationWillTerminate"); }