Catching off event UIImagePickerController on home button

I am working on a bug in my program, but I cannot find a solution.

When the user opens the camera, UIImagePickerController is displayed and works fine. Although, when he presses the home button on the iPhone, I want to remove the object from NSMutableArray.

For example: The user opens the camera. The object is added to NSMutableArray in another class. The user presses the home button. The object must be deleted.

I cannot call the remove method when the application moves to the background, because I need another object so that it stays in the array for location services.

Is there a way to catch an event when either you press the home button or when the UIImagePicker is closed by the event itself on the home button?

+3
source share
2 answers

You will have to post messages. To do this, in the appDelegate method:

 - (void)applicationDidEnterBackground:(UIApplication *)application
 {
   [[NSNotificationCenter defaultCenter] postNotificationName:@"objectRemover" object:nil];
 }

Now you have opened the UIImagePickerController in your view controller and its viewDidLoad method

-(void)viewDidLoad
{
 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(removeObject) name:@"objectRemover" object:nil];
}

add a selector method to your view controller, you will delete your object as it will be called when the home button is pressed.

-(void)objectRemover
{
   // Your code remove object from array
}
+2
source

In the class ... AppDelegate.m you will find the following useful methods

- (void)applicationWillResignActive:(UIApplication *)application {
- (void)applicationDidEnterBackground:(UIApplication *)application {
- (void)applicationWillTerminate:(UIApplication *)application {
0
source

All Articles