在炒作的localNotification performe行动

时间:2013-11-09 02:13:39

标签: ios notifications action uilocalnotification

我试图在触发器相等时从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];
}

提前致谢

0 个答案:

没有答案