UILocalNotification 本地通知的用法

来源:互联网 发布:男生淘宝图片2017 编辑:程序博客网 时间:2024/05/17 07:46

本文主要介绍代码用法.理论请参见这篇文章.http://blog.csdn.net/bihailantian1988/article/details/7383197

- (void)viewDidLoad{    [super viewDidLoad];// Do any additional setup after loading the view.    UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];    [btn setFrame:CGRectMake(100, 100, 100, 100)];    [btn setTitle:@"add" forState:UIControlStateNormal];        [btn addTarget:self action:@selector(add) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn];        UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];    [btn2 setFrame:CGRectMake(100, 200, 100, 100)];    [btn2 setTitle:@"look" forState:UIControlStateNormal];    [btn2 addTarget:self action:@selector(look) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn2];        UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeSystem];    [btn3 setFrame:CGRectMake(100, 300, 100, 100)];    [btn3 setTitle:@"delete" forState:UIControlStateNormal];    [btn3 addTarget:self action:@selector(clean) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:btn3];    }- (void)add{    NSLog(@"add点击事件");    //创建一个本地通知UILocalNotifition    UILocalNotification *ln = [[UILocalNotification alloc] init];    //需要制定初始化的时间    ln.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];//5秒之后    //需要制定一个弹出的内容信息    ln.alertBody = @"快起来啊,闹你妹要响了!";    //查看按钮,显示的文字    ln.alertAction = @"打开";    //打开程序,显示的启动画面    ln.alertLaunchImage = @"001.jpg";    //提醒时候播放的音频    ln.soundName = @"短信02.caf";    //应用程序图标上的数字    ln.applicationIconBadgeNumber = 2;    //重复频率    ln.repeatInterval = NSCalendarUnitMinute;    //将配置好的文件加到操作系统中    UIApplication *application = [UIApplication sharedApplication];    [application scheduleLocalNotification:ln];    }- (void)look{    NSLog(@"look点击事件");    UIApplication *application = [UIApplication sharedApplication];    NSArray *arr = [application scheduledLocalNotifications];    NSLog(@"%@",arr);    }- (void)clean{    NSLog(@"clean点击事件");    UIApplication *application = [UIApplication sharedApplication];    [application cancelAllLocalNotifications];    }


0 0
原创粉丝点击