所以我在ViewController.m中有一个方法,只需按一下按钮就可以发布通知(到通知中心)
来自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!");
}
}
我想要做的是在以下方法中使用上面的方法(在AppDelegate.m中):
- (void)applicationDidEnterBackground:(UIApplication *)application
答案 0 :(得分:1)
您可以注册以在视图控制器中接收通知,以便在应用程序进入后台时收到通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buttonPush:) name:UIApplicationWillResignActiveNotification object:nil];