关于IOS9的本地通知方法
来源:互联网 发布:郑州八度网络 编辑:程序博客网 时间:2024/06/14 01:47
欢迎使用Markdown编辑器写博客
做stone的本地通知,也就是连接之后,app进入后台或者锁屏,按下stone的按键,手机端需要有本地通知。
实现方法是:
1、需要实现后台APP BLE继续运行:
2、在按键按下的方法里面添加:
UIApplication *app = [UIApplication sharedApplication];
if ((app.applicationState == UIApplicationStateBackground) || (app.applicationState == UIApplicationStateInactive)) { if (keyValue != 0) { NSLog(@"Background Key Value %d", keyValue); UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) { return; } localNotif.soundName = UILocalNotificationDefaultSoundName; localNotif.applicationIconBadgeNumber = keyValue; localNotif.alertBody = [NSString stringWithFormat:@"You pressed button %d", keyValue]; //localNotif.alertAction = @"Deanna got something for you"; localNotif.hasAction = NO; //注意 : 这里是立刻弹出通知,其实这里也可以来定时发出通知,或者倒计时发出通知 [app presentLocalNotificationNow:localNotif]; } }
3、更为重要的是需要在AppDelegate.m中来注册通知
- (BOOL)application:(UIApplication )application didFinishLaunchingWithOptions:(NSDictionary )launchOptions
{
if ([[UIDevice currentDevice].systemVersion doubleValue]>=8.0) {
UIUserNotificationSettings* settings=[UIUserNotificationSettings
settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound
categories:nil];
[application registerUserNotificationSettings:settings];}
return YES;
}
做完上面几个步骤,就可以实现通知了。
0 0
- 关于IOS9的本地通知方法
- ios海哥开发笔记 (海哥原创,UILocalNotification本地通知的设置以及iOS9通知新特性 )
- 关于本地通知
- IOS8关于本地通知
- 老外些的关于本地通知的教程
- 关于iOS8上本地通知
- 关于iOS8上本地通知
- 关于iOS8上本地通知接收不到的问题
- 关于iOS8上本地通知接收不到的问题
- 关于iOS8下注册本地通知的一些笔记
- iOS关于本地推送通知的简单用法
- 关于一个每日定时推送本地通知的问题
- 本地通知的使用
- 本地通知的使用
- 本地通知的使用
- IOS 本地推送通知方法
- iOS实现本地通知(local notification)的方法
- iOS9一下本地推送的代码实现
- @NotNull和@NotEmpty和@NotBlank区别
- 友盟分享集成
- OCP-1Z0-051-2015-43题
- 常用WebService(逐渐更新)
- 人脸检测“Face detections without bells and whistles”
- 关于IOS9的本地通知方法
- wdcp 升级PHP5.3版本,自带支持pdo_mysql组件方法
- struts2的核心
- eclipse 的 working set 里,open project 重复显示的问题
- 页面响应事件跳转的两种方法
- 网络层—路由选择协议
- 简单算法—N皇后构造解,n>=4
- asp.net关于post和get传值的问题
- linux下打包文件夹(不保留路径)