1

当firedate相等时,我正在尝试从Appdelegate运行-(void)doaction,但它只显示initWithTitle,而cancelButtonTitle它没有执行整个操作并且它崩溃然后我点击cancelButton,我没有'不知道为什么请帮忙。这是我尝试过的。

视图控制器.m

 NSDate *pickerDate = [self.datePicker date];

[[NSCalendar currentCalendar] rangeOfUnit:NSMinuteCalendarUnit
                                startDate:&pickerDate
                                 interval:NULL
                                  forDate:pickerDate];

[[UIApplication sharedApplication] cancelAllLocalNotifications];
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
UIApplication *app = [UIApplication sharedApplication];


if (localNotification) {


    localNotification.fireDate = pickerDate;
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.applicationIconBadgeNumber = 1;
    [app scheduleLocalNotification:localNotification];

 }

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];

}

那个行动。

- (void)doaction{

if (!recorder.recording){
    player = [[AVAudioPlayer alloc] initWithContentsOfURL:recorder.url error:nil];
    [player setDelegate:self];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"name" message:self.wakeMessage.text delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
    player.numberOfLoops = -1;
    [player play];

    [alert show];


}
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
 if (buttonIndex==0) {
    [player stop];
}

在 Appdeleget.m

- (void)application:(UIApplication *)application didReceiveLocalNotification(UILocalNotification *)localNotification { 
    localNotification.applicationIconBadgeNumber = 1;

ViewController * vc = [[ViewController alloc]init];
    [vc doaction];
}

提前致谢

4

0 回答 0