我试图在触发器相等时从Appdelegate运行 - (void)doaction,但它只显示initWithTitle,而cancelButtonTitle它不执行整个动作然后崩溃然后我点击cancelButton,我不知道为什么PLZ帮忙。这是我尝试过的。
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];
}
提前致谢