Brian
Brian

Reputation: 73

IOS Using method from ViewController.m in AppDelegate.m?

So I have a method in ViewController.m that posts a notification (to notification center) with a push of a button

heres the method from ViewController.m

- (IBAction)buttonPush:(id)sender {
    //clear NC
    [[UIApplication sharedApplication] cancelAllLocalNotifications];


    //make mutablearray
    NSMutableArray *list = [NSMutableArray array];


    [list addObject:first];
    [list addObject:second];
    [list addObject:third];



    //post notification
    for (UITextField *thing in list) {
        UILocalNotification *notif = [[UILocalNotification alloc] init];
        notif.alertBody = thing.text;
        [[UIApplication sharedApplication] presentLocalNotificationNow:notif];
        NSLog(@"looped!");

    }


    }

what i want to do is use the above method in the following method (which is in AppDelegate.m):

- (void)applicationDidEnterBackground:(UIApplication *)application

Upvotes: 0

Views: 147

Answers (1)

Brandon Campbell
Brandon Campbell

Reputation: 394

You can register to receive a notification in your view controller to be notified when the application will enter the background:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buttonPush:) name:UIApplicationWillResignActiveNotification object:nil];

Upvotes: 1

Related Questions