firedate が等しいときに Appdelegate から -(void)doaction を実行しようとしていますが、initWithTitle と cancelButtonTitle のみが表示され、アクション全体が実行されず、クラッシュしてから cancelButton をタップします。なぜ助けてくれるのかわかりません。これが私が試したことです。
Viewcontroller.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];
}
前もって感謝します