美文网首页面试集锦iOS知识专题
iOS开发本地通知(每天3点半发送消息推送)

iOS开发本地通知(每天3点半发送消息推送)

作者: wwwwwwww1 | 来源:发表于2016-06-27 15:54 被阅读2268次

NSDate *now = [NSDate date];
//取得系统时间
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
components = [calendar components:unitFlags fromDate:now];
NSInteger hour = [components hour];
NSInteger min = [components minute];
NSInteger sec = [components second];
NSInteger week = [components weekday];
NSLog(@"现在是%ld:%ld:%ld,周%ld",hour,min,sec,week);

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//设置时区(跟随手机的时区)
localNotification.timeZone = [NSTimeZone defaultTimeZone];
if (localNotification) {
    localNotification.alertBody = @"消息推送消息推送";
    localNotification.alertAction = @"打开";
    //小图标数字
    localNotification.applicationIconBadgeNumber = 0;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSDate *date = [formatter dateFromString:@"15:30:00"];
    //通知发出的时间
    localNotification.fireDate = date;
}
//循环通知的周期
localNotification.repeatInterval = kCFCalendarUnitDay;

//设置userinfo方便撤销
NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
localNotification.userInfo = info;
//启动任务
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
 */
/*
for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) {
    if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) {
        [[UIApplication sharedApplication] cancelLocalNotification:obj];
    }
}




// 设置一个按照固定时间的本地推送
NSDate *now = [NSDate date];
//取得系统时间
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDateComponents *components = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitWeekday | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
components = [calendar components:unitFlags fromDate:now];
NSInteger hour = [components hour];
NSInteger min = [components minute];
NSInteger sec = [components second];
NSInteger week = [components weekday];
WDLog(@"现在是%ld:%ld:%ld,周%ld",hour,min,sec,week);

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
//设置时区(跟随手机的时区)
localNotification.timeZone = [NSTimeZone defaultTimeZone];
if (localNotification) {
    localNotification.alertBody = @"消息推送消息推送";
    localNotification.alertAction = @"打开";
    //小图标数字
    localNotification.applicationIconBadgeNumber = 0;
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"HH:mm:ss"];
    NSDate *date = [formatter dateFromString:@"15:30:00"];
    //通知发出的时间
    localNotification.fireDate = date;
}
//循环通知的周期
localNotification.repeatInterval = kCFCalendarUnitDay;

//设置userinfo方便撤销
NSDictionary *info = [NSDictionary dictionaryWithObject:@"name" forKey:@"key"];
localNotification.userInfo = info;
//启动任务
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
 */
/*
for (UILocalNotification *obj in [UIApplication sharedApplication].scheduledLocalNotifications) {
    if ([obj.userInfo.allKeys containsObject:kLocalNotificationKey]) {
        [[UIApplication sharedApplication] cancelLocalNotification:obj];
    }
}
//直接取消全部本地通知
//[[UIApplication sharedApplication] cancelAllLocalNotifications];

相关文章

  • iOS开发本地通知(每天3点半发送消息推送)

    NSDate *now = [NSDate date];//取得系统时间NSCalendar *calendar ...

  • ios10前后推送基本使用

    一、推送的分类 本地推送通知“本地”可以理解为”不联网”;即使没有网络情况下,也可以推送通知消息通知发送方: 开发...

  • 本地推送

    本地推送通知“本地”可以理解为”不联网”;即使没有网络情况下,也可以推送通知消息通知发送方: 开发人员负责在APP...

  • iOS-消息推送

    iOS 消息推送包括远程推送通知(Remote Notification)和本地推送通知(Local Notifi...

  • iOS问题解决(三):模拟器收不到UILocalNotifica

    通知功能是iOS应用开发经常会碰到的需求,iOS应用的通知分为本地通知和远程通知(即消息推送),Apple dev...

  • 推送通知

    推送通知的分类 本地推送通知本地推送通知可以理解为不联网,即使没有网络也可以推送通知通知发送方:开发人员负责在AP...

  • iOS 消息推送 - 本地推送,兼顾iOS8 categorys

    本地推送 1、申请权限,开启通知2、app 主动向设备的通知中心发送本地消息3、在设定的触发时间,产生消息推送 1...

  • iOS 发送本地推送通知

    App在后台的情况希望通知用户看到信息时使用本地推送通知实现。1.导入系统框架 2.注册本地通知样式 3.清除之前...

  • iOS消息通知产品设计

    ios消息类型有本地通知、推送消息以及系统消息。 消息类型: 本地通知:是由ios设备生成并发布的,无论应用程序是...

  • iOS本地通知和远程推送

    iOS 本地通知和远程推送 推送通知的应用,可以推送最新的消息给用户,获得更多的关注。推送分为本地推送和远程推送两...

网友评论

    本文标题:iOS开发本地通知(每天3点半发送消息推送)

    本文链接:https://www.haomeiwen.com/subject/iqizdttx.html