实用知识:基于监听位置的本地通知 使用方法
2016-05-12 22:05
337 查看
#import "AppDelegate.h" #import <CoreLocation/CoreLocation.h> @interface AppDelegate () <CLLocationManagerDelegate> @property (strong, nonatomic) CLLocationManager *manager; @end @implementation AppDelegate - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { /*================= 通知权限 =================*/ UIUserNotificationType type = UIUserNotificationTypeBadge | UIUserNotificationTypeSound | UIUserNotificationTypeAlert; // UIUserNotificationSettings 表示App可以使用的通知的展示类型(声音, 边缘数字, 弹窗) // category 是用来配置 按钮的 UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:type categories:nil]; // 注册用户通知的配置(通知使用的类型), (会弹出授权窗口来请求) [[UIApplication sharedApplication] registerUserNotificationSettings:settings]; /*================= 定位权限 =================*/ _manager = [[CLLocationManager alloc] init]; _manager.delegate = self; // [_manager requestWhenInUseAuthorization]; [_manager requestAlwaysAuthorization]; return YES; } #pragma mark - CLLocationManagerDelegate //- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status //{ // //} //- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error //{ // //} @end
#import "ViewController.h" #import <CoreLocation/CoreLocation.h> @interface ViewController () @end @implementation ViewController - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSLog(@"点击了"); /*================= 召召路过云水瑶, 得到通知提醒 =================*/ // 1. 基于位置触发的本地通知 UILocalNotification *notification = [[UILocalNotification alloc] init]; // 2. 参数 // notification.fireDate notification.alertBody = @"欢迎召召, 请上3楼!"; // 触发通知的区域 (区域监听) // When-In-Use与Always都可以使用 // 默认只执行一次 notification.region = [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(23.133916, 113.395557) radius:500 identifier:@"YunShuiYao"]; // 基于区域的通知是否只执行一次 notification.regionTriggersOnce = NO; // 3.添加到调度池中等待调度 [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } @end
相关文章推荐
- UVA10340
- 实验三 进程调度模拟程序
- @IntDef 替代 Enum
- Java并发包Concurrent下Callable和Future实战
- leetcode_347 Top K Frequent Elements
- 并查集小结
- 分页例题
- aardio学习笔记-调用管道
- MySql-数据类型
- 简单易懂的解释c#的abstract和virtual的用法和区别
- Hibernate中cascade与inverse属性的理解
- 前端知识积累
- SoftmaxLayer and SoftmaxwithLossLayer 代码解读
- phpstudy 安装选择,iis+php组合,如何设置伪静态
- 模拟水题,查看二维数组是否有一列都为1(POJ2864)
- 矩阵连乘
- 特殊的css样式
- 线段树&树状数组总结篇
- css动画效果回调处理
- Glib学习(4) 哈希表 Hash Tables