为什么我的本地通知没有出现在我的实际设备上? (iPhone 5c)

Why are my local notifications not appearing on my actual device? (iPhone 5c)

当我传输程序时,本地通知会出现在模拟器中,但不会出现在我的手持设备中。

这是我的操作按钮,它将启动一个计时器,并且根据滑块的值,通知应该每隔 num 分钟出现一次。

- (IBAction)StartTimer:(id)sender {
checker = 1;
[self pressed];
NSString *title = @"Shower Alarm";
NSString *message = @"Your alarm will start now";
NSString *okAlert = @"Ok";
UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okButton = [UIAlertAction actionWithTitle:okAlert style:UIAlertActionStyleCancel handler:nil];

[alert addAction:okButton];
[self presentViewController:alert animated:YES completion:nil];

check.text = [NSString stringWithFormat: @"Showering In Progress..."];
//[self Timer];

dispatch_async(dispatch_get_main_queue(), ^{

    num1 = num*60.0;
    _ShowerTimer = [NSTimer scheduledTimerWithTimeInterval:num1
                                                    target:self
                                                  selector:@selector(notification)
                                                  userInfo:nil
                                                   repeats:YES];});}

这是我的通知方法被定时器@selector调用

-(void)notification{

//NSDate *alarmTime = [[NSDate date] dateByAddingTimeInterval:num];
UIApplication *app = [UIApplication sharedApplication];

UILocalNotification *notifyAlarm = [[UILocalNotification alloc] init];

// get current date/time
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
//NSLog(@"User's current time in their preference format:%@",currentTime);

notifyAlarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0];
notifyAlarm.timeZone = [NSTimeZone defaultTimeZone];
notifyAlarm.repeatInterval = 0;
notifyAlarm.soundName = @"";
notifyAlarm.alertBody = [NSString stringWithFormat:@"Notified at %@",currentTime];
[app scheduleLocalNotification:notifyAlarm];}

我也在我的 didFinishLaunching 方法中请求了许可。我阅读了有关 didReceiveLocalNotification 的内容,但这会影响我的设备而不是模拟器吗?我可以锁定我的模拟器,我仍然会收到通知,但我的设备不会收到任何通知。

不用定时器,调用

[self notification]

并修改

notifyAlarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:1.0];

像这样有 60 秒

notifyAlarm.fireDate = [NSDate dateWithTimeIntervalSinceNow:60.0];

。在 phone 上将应用程序置于后台时,它可能会关闭。即使应用程序正在后台关闭或冻结,安排计时器也会着火。有用吗?