ios 本地推送的添加和取消
2012-11-29 14:36
651 查看
//取消
- (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];
}
}
}
//添加
- (void)addClock:(int)clockID(时间) body:(NSString *)name(文字)
{
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就是得到的时间,传给方法就可以了
- (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];
}
}
}
//添加
- (void)addClock:(int)clockID(时间) body:(NSString *)name(文字)
{
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本地推送与取消本地通知—UILocalNotification的使用
- iOS 10 添加本地推送(Local Notification)
- iOS-OC-本地推送和取消本地推送服务
- iOS 10 添加本地推送(Local Notification)
- iOS - iOS10 添加本地推送(Local Notification)
- ios开发之-本地推送通知
- iOS本地推送
- iOS推送(一):本地推送
- (七十三)iOS本地推送通知的实现
- ios本地推送
- iOS的本地消息推送。
- iPhone/iPad开发通过LocalNotification实现iOS定时本地推送功能
- iOS 通讯录添加了本地打电话功能
- IOS 推送(本地推送、远程推送、三方推送[极光推送])
- iOS开发 -- 为本地文件添加自定义属性的工具类
- iOS 实现本地推送
- ios本地推送信息互动
- iOS推送:实现本地推送
- iOS 10本地推送
- iOS推送:本地通知UILocalNotification