0

所以我在 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
4

1 回答 1

1

您可以注册以在您的视图控制器中接收通知,以便在应用程序进入后台时收到通知:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(buttonPush:) name:UIApplicationWillResignActiveNotification object:nil];
于 2013-07-09T17:01:44.543 回答