UILocalNotification 本地通知的用法

本文主要介紹代碼用法.理論請參見這篇文章.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];
    
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章