欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS本地推送簡單實(shí)現(xiàn)代碼

 更新時(shí)間:2016年09月21日 14:21:04   作者:幸福小禰  
這篇文章主要為大家詳細(xì)介紹了iOS本地推送簡單實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文為大家分解介紹了iOS本地推送代碼的三步驟,供大家參考,具體內(nèi)容如下

第一步:創(chuàng)建本地推送

// 創(chuàng)建一個(gè)本地推送
UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
//設(shè)置10秒之后
NSDate *pushDate = [NSDate dateWithTimeIntervalSinceNow:10];
if (notification != nil) {
 // 設(shè)置推送時(shí)間
 notification.fireDate = pushDate;
 // 設(shè)置時(shí)區(qū)
 notification.timeZone = [NSTimeZone defaultTimeZone];
 // 設(shè)置重復(fù)間隔
 notification.repeatInterval = kCFCalendarUnitDay;
 // 推送聲音
 notification.soundName = UILocalNotificationDefaultSoundName;
 // 推送內(nèi)容
 notification.alertBody = @"推送內(nèi)容";
 //顯示在icon上的紅色圈中的數(shù)子
 notification.applicationIconBadgeNumber = 1;
 //設(shè)置userinfo 方便在之后需要撤銷的時(shí)候使用
 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];
 // 圖標(biāo)上的數(shù)字減1
 application.applicationIconBadgeNumber -= 1;
}

第三步:解除本地推送

// 獲得 UIApplication
UIApplication *app = [UIApplication sharedApplication];
//獲取本地推送數(shù)組
NSArray *localArray = [app scheduledLocalNotifications];
//聲明本地通知對(duì)象
UILocalNotification *localNotification;
if (localArray) {
 for (UILocalNotification *noti in localArray) {
  NSDictionary *dict = noti.userInfo;
  if (dict) {
   NSString *inKey = [dict objectForKey:@"key"];
   if ([inKey isEqualToString:@"對(duì)應(yīng)的key值"]) {
    if (localNotification){
     [localNotification release];
     localNotification = nil;
    }
    localNotification = [noti retain];
    break;
   }
  }
 }
 
 //判斷是否找到已經(jīng)存在的相同key的推送
 if (!localNotification) {
  //不存在初始化
  localNotification = [[UILocalNotification alloc] init];
 }
 
 if (localNotification) {
  //不推送 取消推送
  [app cancelLocalNotification:localNotification];
  [localNotification release];
  return;
 }
}

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論