在项目中需要用上本地推送,测试了下,发现有问题,居然无法实现,检查了下,也在网上找了写资料,发现代码是没有问题的,可就是无法执行!
换了太设备测试了下,没有任何的问题,一下是正确代码
或许是设备有问题,如果那位大神知道,求回复!
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIButton *but = [[UIButton alloc] initWithFrame:CGRectMake(30, 100, 100, 30)];
but.backgroundColor = [UIColor blueColor];
[but addTarget:self action:@selector(vvvvvvvvvv) forControlEvents:UIControlEventTouchDown];
[but setTitle:@"通知" forState:UIControlStateNormal];
[but setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[self.view addSubview:but];
}
-(void)vvvvvvvvvv{
UILocalNotification *notification = [[UILocalNotification alloc] init];
if (notification) {
// 设置通知的提醒时间
NSDate *currentDate = [NSDate date];
notification.timeZone = [NSTimeZone defaultTimeZone]; // 使用本地时区
notification.fireDate = [currentDate dateByAddingTimeInterval:3];
// 设置重复间隔 不重复
notification.repeatInterval = 0;
// 设置提醒的文字内容
notification.alertBody = @"hello,boy!";
// 通知提示音 使用默认的
notification.soundName= UILocalNotificationDefaultSoundName;
// 将通知添加到系统中
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
}
}
// app delegate //
-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello"
message:notification.alertBody
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert show];
}