• iphone 定时提醒


    //定时提醒
    -(void)schedulNotificationWithYear:(int)y andMonth:(int)m andDay:(int)d andHour:(int)h andMintu:(int)mi andMsg:(NSString *)msg{
        
        // Set up the fire time
        NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];
        NSDateComponents *dateComps = [[NSDateComponents alloc] init];
        [dateComps setDay:d];
        [dateComps setMonth:m];
        [dateComps setYear:y];
        [dateComps setHour:h];
    // Notification will fire in one minute
        [dateComps setMinute:mi];
    [dateComps setSecond:0];
        NSDate *itemDate = [calendar dateFromComponents:dateComps];
        [dateComps release];
        
        UILocalNotification *localNotif = [[UILocalNotification alloc] init];
        if (localNotif == nil)
            return;
        localNotif.fireDate = itemDate;
        localNotif.timeZone = [NSTimeZone defaultTimeZone];
        
    // Notification details
        localNotif.alertBody = msg;
    // Set the action button
        localNotif.alertAction = @"查看";
        
        localNotif.soundName = UILocalNotificationDefaultSoundName;
        //    localNotif.applicationIconBadgeNumber = 1;
        
    // Specify custom data for the notification
        NSDictionary *infoDict = [NSDictionary dictionaryWithObject:@"someValue" forKey:@"someKey"];
        localNotif.userInfo = infoDict;
        
    // Schedule the notification
        [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
        [localNotif release];
    }
    
    在AppDelegate.m中添加如下代码,相当于回调函数
    
    
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notif {
    
        UITextView *tv = (UITextView *)[[application keyWindow] viewWithTag:11];
        NSString *status = [NSString stringWithFormat:@"%@", [notif description]];
        tv.text = status;
        //添加处理代码
    }
  • 相关阅读:
    自己实现简单Spring Ioc
    java中动态代理的实现
    Token以及签名signature的设计与实现
    Spring boot整合jsp
    spring boot+mybatis整合
    java并发基础(六)--- 活跃性、性能与可伸缩性
    java并发基础(五)--- 线程池的使用
    java并发基础(四)--- 取消与中断
    java并发基础(三)--- 任务执行
    java并发基础(二)
  • 原文地址:https://www.cnblogs.com/lm3515/p/2546101.html
Copyright © 2020-2023  润新知