您的位置:首页 > 产品设计 > UI/UE

ios海哥开发笔记 (海哥原创,UILocalNotification本地通知的设置以及iOS9通知新特性 )

2016-03-10 14:43 471 查看
注意:Xcode7,iOS9 ,为什么同样的一段代码在iOS8中能弹出本地通知,现在不行了呢 ,不要急,慢慢往下看吗?

一。介绍,一个APP发送本地通知是非常常见的,小编就简单介绍下本地通知

想要获取用户权限,要添加以下代码在AppDelegate.m文件中。

- (BOOL)application:(UIApplication
*)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions

{

UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert
| UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:setting];

return
YES;

}

1.现在一个个介绍作用了,苹果是非常在意用户体验的,所以现在开始,本地通知的内容都要一一显示

UIUserNotificationTypeNone 表示不推送

UIUserNotificationTypeBadge 表示接受图标右上角的数值改变

UIUserNotificationTypeSound 表示接受声音

UIUserNotificationTypeAlert 表示接受提醒(横幅/弹窗)

你想要获取用户哪几种权限,全部写上即可,中间用” | ” 符号隔开。
二,剩下的就是开启本地通知的代码了

UILocalNotification *notification = [[UILocalNotification alloc] init];

notification.alertAction = @"开始玩游戏"; //
操作标题

notification.alertBody = @"您已经一天没查看了,是上了天堂了吗";

notification.applicationIconBadgeNumber = 8;// 提醒数字

notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:5];// 几秒后弹出通知

// notification.repeatInterval = 2;

// 注册通知

[[UIApplication sharedApplication] scheduleLocalNotification:notification];

这样就能轻松解决本地通知问题了,建议扒一扒UILocalNotification的API,就那几个属性,一一了解呗。

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