IOS本地定时推送通知
2015-12-23 09:28
351 查看
void scheduleLocalNotification(int secondsAfter, std::string
description ,std::string key)
{
//获取本地推送数组
NSArray *localArray =
[[UIApplication sharedApplication]
scheduledLocalNotifications];
//声明本地通知对象
// UILocalNotification
*localNotification;
if (localArray)
{
for
(UILocalNotification *noti in localArray)
{
NSDictionary
*dict = noti.userInfo;
if
(dict)
{
NSString* strKey = [NSString stringWithCString:key.c_str()
encoding:NSUTF8StringEncoding];
NSString
*inKey = [dict objectForKey:strKey];
if
([inKey isEqualToString:strKey])
{
return;
}
}
}
}
// if (!localNotification)
{
NSDate
*itemDate = [NSDate dateWithTimeIntervalSinceNow:0];
UILocalNotification
*localNotif = [[UILocalNotification alloc] init];
if
(localNotif == nil)
return;
localNotif.fireDate
= [itemDate dateByAddingTimeInterval:secondsAfter];
localNotif.timeZone
= [NSTimeZone defaultTimeZone];
localNotif.alertBody
= [NSString stringWithUTF8String:description.c_str()];
localNotif.alertAction
= NSLocalizedString(@"查看", nil);
localNotif.soundName
= UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber
= 1;
NSString* strKey = [NSString stringWithCString:key.c_str()
encoding:NSUTF8StringEncoding];
NSDictionary
*infoDict = [NSDictionary dictionaryWithObject:strKey
forKey:strKey];
localNotif.userInfo
= infoDict;
[[UIApplication
sharedApplication] scheduleLocalNotification:localNotif];
[localNotif
release];
}
}
description ,std::string key)
{
//获取本地推送数组
NSArray *localArray =
[[UIApplication sharedApplication]
scheduledLocalNotifications];
//声明本地通知对象
// UILocalNotification
*localNotification;
if (localArray)
{
for
(UILocalNotification *noti in localArray)
{
NSDictionary
*dict = noti.userInfo;
if
(dict)
{
NSString* strKey = [NSString stringWithCString:key.c_str()
encoding:NSUTF8StringEncoding];
NSString
*inKey = [dict objectForKey:strKey];
if
([inKey isEqualToString:strKey])
{
return;
}
}
}
}
// if (!localNotification)
{
NSDate
*itemDate = [NSDate dateWithTimeIntervalSinceNow:0];
UILocalNotification
*localNotif = [[UILocalNotification alloc] init];
if
(localNotif == nil)
return;
localNotif.fireDate
= [itemDate dateByAddingTimeInterval:secondsAfter];
localNotif.timeZone
= [NSTimeZone defaultTimeZone];
localNotif.alertBody
= [NSString stringWithUTF8String:description.c_str()];
localNotif.alertAction
= NSLocalizedString(@"查看", nil);
localNotif.soundName
= UILocalNotificationDefaultSoundName;
localNotif.applicationIconBadgeNumber
= 1;
NSString* strKey = [NSString stringWithCString:key.c_str()
encoding:NSUTF8StringEncoding];
NSDictionary
*infoDict = [NSDictionary dictionaryWithObject:strKey
forKey:strKey];
localNotif.userInfo
= infoDict;
[[UIApplication
sharedApplication] scheduleLocalNotification:localNotif];
[localNotif
release];
}
}
相关文章推荐
- IOS中各种动画特效的实现
- 详解iOS开发中app的归档以及偏好设置的存储方式
- IOS中通知中心(NSNotificationCenter)的使用总结
- mac 操作系统 ios操作系统
- 开发使用 iBeacon 的 iOS 7 应用
- 统计iOS工程代码行数
- iOS开发 关于iBeacon
- iOS开发—获取系统键盘高度
- IOS视频播放器VKVideoPlayer简单教程
- iosclient暑期“动画屋“活动项目总结
- iOS-QuartzCore(CAAnimation.h--解读)
- iOS导航控制器
- iOS navigationcontroller 的导航条的设置
- iOS各个版本的特点
- IOS 动画组
- IOS CALayer
- IOS 逐帧动画
- IOS 转场动画 -CATransition
- iOS- GCD总结
- iOS - block语法块