jiafuyang

[2]-----------IOS程序中如何进行本地推送?-----------

2.1,先征求用户同意

复制代码
1 /**
2      *  IOS8以后,推送通知需要征求用户同意
3      */
4     UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil];
5     [application registerUserNotificationSettings:settings];
6     NSLog(@"当前APP没有死掉----%@",launchOptions);
复制代码

 

2.2创建本地通知对象(UILocalNotification 这个类来管理,设置什么时候通知,通知的消息内容等)

UILocalNotification *localN = [UILocalNotification new];

 

  设置处理通知的一些属性

  fireDate时间 

  alertTitle标题

  alertBody通知内容

  soundName声音,

  applicationIconBadgeNumber图标数字

  alertAction锁屏状态下的通知消息

  其他参数:

    timeZone时区

    repeatInterval重复间隔...

    alertLaunchImage点击通知的启动图片

2.3安排通知

[[UIApplication sharedApplication]scheduleLocalNotification:(UILocalNotification*)];

 

2.4安排通知后,就会在手机上收到了,此时需要处理点击接受到的通知后的处理

 /** 接收本地通知  程序在前台 程序在后台 锁屏 */

- (void) application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification

{

    NSLog(@"%@",notification);

}

2.5 可以根据需求,取消通知.

--------------放xcode截图----------最后放源码------注意是折叠源码-------------

-------再感受一下通知-----当程序被用户向上划掉了也能接收通知-------

分类:

技术点:

相关文章: