- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//注册通知
if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)])
{
[application registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
}
UIButton *btn=[UIButton buttonWithType:UIButtonTypeSystem];
[btn setTitle:@"开始" forState:UIControlStateNormal];
btn.frame=CGRectMake(100, 100, 100, 30);
[self.window addSubview:btn];
[btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)btnClick:(UIButton *)bt
{
//本地消息推送
//创建一个本地推送的任务
UILocalNotification *local = [[UILocalNotification alloc] init];
//设定时间,10秒之后开启
local.fireDate = [NSDate dateWithTimeIntervalSinceNow:10];
//设定内容
local.alertBody = @"亲~你该起床啦,不要赖床哦";
//设定提示的声音,这个声音是你工程中就有的声音,它支持WAV,CAF等众多格式
local.soundName = @"音效.caf";
//设置小红点徽标
int num = [UIApplication sharedApplication].applicationIconBadgeNumber;
if (num == 0) {
num = 1;
}else{
num++;
}
//设置小红点推送的内容
local.applicationIconBadgeNumber = num;
//把推送加入到我们系统管理内
[[UIApplication sharedApplication] scheduleLocalNotification:local];
//以上内容10秒后运行
}
转载于:https://my.oschina.net/haitangliuxing/blog/660101