您的位置:首页 > 其它

本地推送

2014-11-04 16:29 351 查看
对于iOS来说有两种推送 

#1.远程推送  

#2.本地推送

接下来主要将的是本地推送

-(void)joinNotificationPush
{

UILocalNotification *localNotification=[[UILocalNotification alloc]init];
if (localNotification) {

/*设置1秒后相应通知*/

NSDate *pushDate=[NSDate dateWithTimeIntervalSinceNow:1];

localNotification.fireDate=pushDate;

/*设置时区*/

localNotification.timeZone=[NSTimeZone defaultTimeZone];

/*设置重复推送的类型*/

localNotification.repeatInterval=kCFCalendarUnitDay;

/*设置推送声音类型*/

localNotification.soundName=UILocalNotificationDefaultSoundName;

/*设置推送的内容*/

localNotification.alertBody =@"XXX  你妈妈 叫你回家吃饭!";

/*设置推送时的图片*/

localNotification.alertLaunchImage=[NSString stringWithFormat:@"3"];

/*设置应用头标红色徽章次数*/

localNotification.applicationIconBadgeNumber=10;

/* 设置通知表示*/

NSDictionary *userInfoDic=[NSDictionary dictionaryWithObject:@"LGW" forKey:@"GW"];

localNotification.userInfo=userInfoDic;

/*判断当前通知已存在*/

UIApplication *app=[UIApplication sharedApplication];
BOOL stauts=YES;
for (UILocalNotification *localNotificate in app.scheduledLocalNotifications) {
if (localNotification.userInfo==localNotificate.userInfo) {
stauts=NO;
}
}

if (stauts) {
[app scheduleLocalNotification:localNotification];
}

}

}

/*取消通知根据本地通知标识*/

-(void)cancelNotificationPush
{
UIApplication *app=[UIApplication sharedApplication];
NSArray *notificationary=[app scheduledLocalNotifications];
for (UILocalNotification *location in notificationary) {
NSDictionary *dic=[location userInfo];
if (dic) {
NSString *key=[dic objectForKey:@"GW"];
if ([key isEqualToString:@"LGW"]) {
[app cancelLocalNotification:location];
break;
}
}
}

}


#3.响应点击通知栏回掉  From Appdelegate.m

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"deviceToken didReceive");

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