在
在AppDelegate里面用这个方法;
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil) {
return;
}
//设置本地通知的触发时间(如果要立即触发,无需设置),这里设置为20妙后
localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
//设置本地通知的时区
localNotification.timeZone = [NSTimeZone defaultTimeZone];
//设置通知的内容
localNotification.alertBody = @"dcdcdc";
//设置通知动作按钮的标题
localNotification.alertAction = @"查看";
//设置提醒的声音,可以自己添加声音文件,这里设置为默认提示声
localNotification.soundName = UILocalNotificationDefaultSoundName;
//设置通知的相关信息,这个很重要,可以添加一些标记性内容,方便以后区分和获取通知的信息
//在规定的日期触发通知
localNotification.userInfo = @{
@"icon" :@"zjjc",
@"title" : @"cdcdc"
};
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];