您的位置:首页 > 移动开发 > IOS开发

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];

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: