zoukankan      html  css  js  c++  java
  • 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;
        //添加处理代码
    }
  • 相关阅读:
    ES学习(十)
    ES学习(九)
    ES学习(八)
    ES学习(七)--documentAPI
    ES学习(六)--shard和replica机制
    ES学习(四)--嵌套聚合、下钻分析、聚合分析
    uniapp中常见的请求方法封装 --来之插件市场(全局方法封装(请求/正则/URI)
    工具/插件
    express中文件的上传 multer
    express中开发常用
  • 原文地址:https://www.cnblogs.com/lm3515/p/2546101.html
Copyright © 2011-2022 走看看