打开APP
未登录
开通VIP,畅享免费电子书等14项超值服
开通VIP
首页
好书
留言交流
下载APP
联系客服
iOS 定时发本地push 实现
plumbiossom
>《代码》
2014.09.01
关注
[cpp]
view plain
copy
//取消之前所有的本地通知
[[UIApplication sharedApplication] cancelAllLocalNotifications];
//清空 icon数量
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
//启动本地通知
UILocalNotification *notification=[[UILocalNotification alloc] init];
if
(notification!=nil)
{
//现在的时间
NSDate *now=[NSDate date];
//获得系统日期
NSCalendar * cal=[NSCalendar currentCalendar];
NSUInteger unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;
NSDateComponents * conponent= [cal components:unitFlags fromDate:now];
NSInteger year=[conponent year];
NSInteger month=[conponent month];
NSInteger day=[conponent day];
//NSString * nsDateString= [NSString stringWithFormat:@"%4d年%2d月%2d日",year,month,day];
//获得当天的12:00 时间
NSString * nsStringDate12 = [NSString stringWithFormat:@
"%d-%d-%d-%d-%d-%d"
,
year, month,day, 12, 0, 0 ];
//根据时间字符串获得NSDate
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@
"YYYY-MM-dd-HH-mm-ss"
];
NSDate * todayTwelve=[dateformatter dateFromString:nsStringDate12];
//然后比较 now跟 todayTwelve那个大,如果已经过了12点,那就设置明天12点
NSComparisonResult dateResult = [now compare:todayTwelve ];
if
(dateResult == NSOrderedDescending )
{
NSDate * tomorrowTwelve = [todayTwelve dateByAddingTimeInterval: 24 * 60 * 60];
notification.fireDate = tomorrowTwelve;
}
else
{
notification.fireDate= todayTwelve;
}
notification.repeatInterval = kCFCalendarUnitDay;
notification.timeZone=[NSTimeZone defaultTimeZone];
notification.applicationIconBadgeNumber = 1;
notification.alertBody=@
"今天还没上线,好多奖励没领呢"
;
notification.alertAction = @
"打开"
;
[[UIApplication sharedApplication] scheduleLocalNotification:notification];
[notification release];
}
- (
void
)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@
"获得本地通知"
);
//点击提示框的打开
application.applicationIconBadgeNumber = 0;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报
。
打开APP,阅读全文并永久保存
查看更多类似文章
猜你喜欢
类似文章
【热】
打开小程序,算一算2024你的财运
为乌克兰搭建“核保护伞”?战后欧洲安全的先例与可能性 | 国政学人
昨天在家看电视,对门35岁的美女来敲门,穿着浴袍像是刚洗完澡的样子,她向屋里望去,随机竟提出这种请求
学会9个说话万能公式,20个沟通技巧,真的会说话了
俄罗斯是什么样的生活?一个住了8年的中国人的描述
哈尔滨731罪证陈列馆,“中国人是出色的实验材料”
萧朗先生笔下的禽鸟图
更多类似文章 >>
生活服务
热点新闻
留言交流
回顶部
联系我们
分享
收藏
点击这里,查看已保存的文章
导长图
关注
一键复制
下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!
联系客服
微信登录中...
请勿关闭此页面
先别划走!
送你5元优惠券,购买VIP限时立减!
5
元
优惠券
优惠券还有
10:00
过期
马上使用
×