深刻解析設計形式中的適配器形式在C++中的應用。本站提示廣大學習愛好者:(深刻解析設計形式中的適配器形式在C++中的應用)文章只能為提供參考,不一定能成為您想要的結果。以下是深刻解析設計形式中的適配器形式在C++中的應用正文
本文為年夜家分化引見了iOS當地推送代碼的三步調,供年夜家參考,詳細內容以下
第一步:創立當地推送
// 創立一個當地推送
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
//設置10秒以後
NSDate *pushDate = [NSDate dateWithTimeIntervalSinceNow:10];
if (notification != nil) {
// 設置推送時光
notification.fireDate = pushDate;
// 設置時區
notification.timeZone = [NSTimeZone defaultTimeZone];
// 設置反復距離
notification.repeatInterval = kCFCalendarUnitDay;
// 推送聲響
notification.soundName = UILocalNotificationDefaultSoundName;
// 推送內容
notification.alertBody = @"推送內容";
//顯示在icon上的白色圈中的數子
notification.applicationIconBadgeNumber = 1;
//設置userinfo 便利在以後須要撤消的時刻應用
NSDictionary *info = [NSDictionary dictionaryWithObject:@"name"forKey:@"key"];
notification.userInfo = info;
//添加推送到UIApplication
UIApplication *app = [UIApplication sharedApplication];
[app scheduleLocalNotification:notification];
}
第二步:吸收當地推送
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification*)notification{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"iWeibo" message:notification.alertBody delegate:nil cancelButtonTitle:@"肯定" otherButtonTitles:nil];
[alert show];
// 圖標上的數字減1
application.applicationIconBadgeNumber -= 1;
}
第三步:消除當地推送
// 取得 UIApplication
UIApplication *app = [UIApplication sharedApplication];
//獲得當地推送數組
NSArray *localArray = [app scheduledLocalNotifications];
//聲明當地告訴對象
UILocalNotification *localNotification;
if (localArray) {
for (UILocalNotification *noti in localArray) {
NSDictionary *dict = noti.userInfo;
if (dict) {
NSString *inKey = [dict objectForKey:@"key"];
if ([inKey isEqualToString:@"對應的key值"]) {
if (localNotification){
[localNotification release];
localNotification = nil;
}
localNotification = [noti retain];
break;
}
}
}
//斷定能否找到曾經存在的雷同key的推送
if (!localNotification) {
//不存在初始化
localNotification = [[UILocalNotification alloc] init];
}
if (localNotification) {
//不推送 撤消推送
[app cancelLocalNotification:localNotification];
[localNotification release];
return;
}
}
以上就是本文的全體內容,願望對年夜家的進修有所贊助,也願望年夜家多多支撐。