ios 本地推送的添加和取消
来源:互联网 发布:网络嗅探器 影音神探 编辑:程序博客网 时间:2024/05/03 14:17
//取消
- (void)shutdownClock:(int)clockID
{NSArray *localNotifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for(UILocalNotification *notification in localNotifications)
{
if ([[[notification userInfo] objectForKey:@"ActivityClock"] intValue] == clockID) {
NSLog(@"Shutdown localNotification:%@", [notification fireDate]);
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
}
}
//添加
{
UILocalNotification *notif1 = [[UILocalNotification alloc] init];
notif1.fireDate = [NSDate dateWithTimeIntervalSinceNow:clockID];
notif1.soundName = UILocalNotificationDefaultSoundName;
notif1.alertBody = [NSString stringWithFormat:name];
//显示在icon上的红色圈中的数子
notif1.applicationIconBadgeNumber = 1;
//设置userinfo 方便在之后需要撤销的时候使用
NSString *strnum=[NSString stringWithFormat:@"%i",clockID];
NSDictionary *info = [NSDictionary dictionaryWithObject:strnum forKey:@"ActivityClock"];
notif1.userInfo = info;
[[UIApplication sharedApplication] scheduleLocalNotification:notif1];
[notif1 release];
}
时间的计算方法
NSDate* now = [NSDate date];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *dateComponents = [gregorian components:(NSHourCalendarUnit
| NSMinuteCalendarUnit
| NSSecondCalendarUnit
) fromDate:now];
[gregorian release];
//当前的"小时"
NSInteger currentHour = [dateComponents hour];
NSInteger currentMin = [dateComponents minute];
//当前“分钟”
//24小时和闹钟时间的计算
int currentTotal = currentHour*3600 + currentMin * 60;
int alarmTotal = hour * 3600 + min *60;
ontimer = alarmTotal - currentTotal;
ontimer就是得到的时间,传给方法就可以了
- ios 本地推送的添加和取消
- iOS-OC-本地推送和取消本地推送服务
- iOS 添加闹钟和取消提醒(本地通知)
- iOS本地推送与取消本地通知—UILocalNotification的使用
- IOS远程推送和本地推送的理解
- 本地推送的设置与取消
- ios 远程推送和本地推送
- IOS 本地推送和远程推送
- 【iOS】本地推送和模拟远程推送
- iOS本地推送和服务器推送
- iOS本地推送和远程推送详解
- iOS远程推送和本地推送
- unity安卓和IOS的本地消息推送
- 本地通知和推送通知 - iOS开发
- iOS本地通知和远程推送
- IOS本地通知和推送通知
- IOS 本地和远程推送通知详解
- ios 本地推送和远程推送(APNS)
- 少走弯路去学习面向对象编程
- sss
- PHP stream_context_create()作用…
- PHP教程:POST数据的三种方法
- 如何从一个php文件向另一个地址pos…
- ios 本地推送的添加和取消
- PHP中使用curl库获取网页内容如何P…
- combobox 处理回车
- stream_context_create解决file_ge…
- How to develop a virtual disk for Windows
- ecmall 实例 创建app
- 剖析ECMALL的登录机制
- ecmall 文件说明
- ECMall 2.0 beta1模板文件列表