IPhone and Location(2)Documents Region Monitoring and Region Sample
The Core Location framework provides 2 ways to detect a user's entry and exit.
a. geographical region monitoring
b. beacon region monitoring
In iOS, regions associated with your app are tracked at all times, including when our app is not running. If a region boundary is crossed while an app is not running, that app is relaunched into the background to handle the event. If the app is suspended when the event occurs, it is woken up and given a short time (10 seconds) to handle the event.
The same when you want more time, call beginBackgroundTaskWithExpirationHandler and call endBackgroundTask after that.
?
Determining the Availability of Region Monitoring
In iOS 7.0 and later, we should always call the isMonitoringAvailableForClass: and authorizationStatus of CLLocationManager
If our app needs to process location updates in the background, be sure to check the backgroundRefreshStatus property of the UIApplication class.
Monitoring Geographical Regions
In iOS 7.0 and later, you define geographical regions using the CLCircularRegion class(old class CLRegion).
To register a region, call the startMonitoringForRegion: method of our CLLocationManager Object.
We store the region information with an identifier.
-(void) registerRegionWithCircularOverlay: (MKCircle*) overlay andIdentifier:(NSString*)identifier {
? ? ?//if the radius is too large, registration fails automatically
? ? ?CLLocationDegrees radius = overlay.radius;
? ? ?if(raids > self.locManager.maximumRegionMonitoringDistance) {
? ? ? ? ? radius = self.locManager.maximumRegionMonitoringDistance;
? ? ?}
? ? ?CLCircularRegion *geoRegion = [[CLCircularRegion alloc]
? ? ? ? ? initWithCenter:overlay.coordinate
? ? ? ? ? ? ? ? ? ? ? radius:radius
? ? ? ? ? ? ? ? ? ?identifier:identifier];
? ? ?[self.locManager startMonitoringForRegion:geoRegion];
}
The monitoring of a geographical region begins immediately, but the event will not happen if you are already in the region.
We can use the method requestStateForRegion method of the CLLocationManger to check whether the user is already inside the boundary of a region.
Regions are a shared system resource and the total number of regions available systemwide is limited. Single app limitation is 20.
If you try to register a region while the space is unavailable, the location manager calls the locationManager:monitoringDidFailForRegion:withError: method of its delegate with the KCLErrorRegionMonitoringFailure error code.
Handling Boundary-Crossing Events for a Geographical Region
a. locationManager: didEnterRegion:
b. locationManager: didExitRegion:
We can customize which boundary-crossing events notify our app by setting the notifyOnEntry and notifyOnExit properties of the CLRegion class(The default value of both properties is YES)
The system does not report boundary crossings until the boundary plus a system-defined cushion distance is exceeded.
Monitoring Beacon Regions
A proximity UUID
A major value
A minor value
If all the stores are monitored by the same UUID, each of which is different by a different major value. In addition, the app can use different minor values to distinguish different departments within the same store.
Defining a Beacon Region to Be Monitored
CLBeaconRegion -----> proximityUUID, major, minor.
To register a beacon region, call the startMonitoringForRegion: of CLLocationManager object.
-(void) registerBeaconRegionWithUUID:(NSUUID *) proximityUUID and Identifier:(NSString*)identifier{
? ? ?CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? identifier:identifier];
? ? ?[self.locManager startMonitoringForRegion:beaconRegion];
}
Handling Boundary-Crossing Events for a Beacon Region
When the enters happen, the location manager calls the locationManager:didEnterRegion, locationManager:didExitRegion.
Determining the Proximity of a Beacon Using Ranging
While the user's device is inside a registered beacon region, apps can use the startRangingBeaconsInRegion of CLLocationManager class to determine the relative proximity of one or more beacons in the region.( Call isRangingAvailable before that.)
Whenever beacons in this specified beacon region come within range, go out of range, or their proximity changes, the location manager calls locationManager:didRangeBeacons:inRegion of its delegate object.
The value of the proximity property of the CLBeacon gives a general sense of the relative distance to a beacon.
- (void) locationManager:(CLLocationManager *) manager
? ? ? ? ? ? ? ?didRangeBeacons:(NSArray *)beacons
? ? ? ? ? ? ? ? ? ? inRegion:(CLBeaconRegion *) region {
? ? ?if([beacons count] > 0) {
? ? ? ? ? CLBeacon *nearestExhibit = [beacons firstObject];
? ? ? ? ? if(CLProximityNear == nearestExhibit.proximity){
? ? ? ? ? ? ? ?[self presentExhibitInfoWithMajorValue:nerestExhibit.major.integerValue];
? ? ? ? ? }else{
? ? ? ? ? ? ? ?[self dismissExhibitInfo]
? ? ? ? ? }
? ? ?}
}
Turn Your iOS Device or Mac into a Beacon
Link your app to CoreBluetooth.framework and?
#import <CoreBluetooth/CoreBluetooth.h>?
Creating and Advertising a Beacon Region
generate a 128-bit UUID
>uuidgen
NSUUID *proximityUUID = [[NSUUID alloc]
? ? ? ? ? ? ? ? ? ? initWithUUIDString:@"A6A71452-13FB-4245-833B-C555A118D383" ];
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? initWithProximityUUID:proximityUUID
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?identifier:@"com.sillycat.easylocation_1"
After that we need to advertise this beacon using CBPeripheralManager from the Core Bluetooth framework.
To advertise peripheral data in Core Bluetooth, we call the startAdvertising method of the CBPeripheralManager.
NSDictionary *beaconPeripheralDate = [beaconRegion peripheralDataWithMessuredPower:nil];
CBPeripheralManager *peripheralManager = [[CBPeripheralManager alloc]
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? initWithDelegate:self queue:nil options:nil];
[peripheralManager startAdvertising:beaconPeripheralData];
Testing Your App's Region Monitoring Support
Region Sample Codes
https://developer.apple.com/library/ios/samplecode/Regions/Introduction/Intro.html
https://github.com/nicktoumpelis/HiBeacons.git
References:
sample codes
https://developer.apple.com/library/ios/search/?q=location+sample
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html#//apple_ref/doc/uid/TP40009497-CH9-SW1
NSOperationQueue
http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
http://software.intel.com/zh-cn/articles/3-nsoperationqueue
详细解决方案
IPhone and Location(二)Documents Region Monitoring and Region Sample
热度:509 发布时间:2016-04-25 05:56:01.0
相关解决方案
- 如何用window.location.href上载文件
- 使用window.location.reload()的有关问题
- window.location.href错误
- iphone 模拟器,该如何处理
- c#c++,android,ios(iphone),php,java视屏课程 散分
- window.location.href不跳转有关问题
- @(ViewBag.Location ? "视频点播") 什么意思解决办法
- IIS 调用Microsoft.Office.Interop.Word.Documents.Open 回到为null
- 怎么让#region.endregion在ashx文件页面下有效
- 有哪位高手用过JPlayer ,进来一下,IPHONE 等设备播放有关问题
- c#调用js中window.location.href进行页面传值?大有关问题!郁闷.
- iframe javascript:location.replace(url)路径有关问题
- 在上传文件时提示对路径“C:\Documents and Settings\Administrator\桌面\6b.jpg”的访问被拒绝解决方法
- window.location.href 在 FireFox 3.0.3 下却不管用,有什么好的解决方法没有
- parent.mainFrame.location 的有关问题
- onclick="parent.location.href='http://www.microsoft.com';"> 在当窗口中打开,小弟我想在框架中的主窗口打开如何做啦
- onclick='window.location.href="xxx.aspx?id="+<%# Eval("id")%>',这样写对吗?该怎么解决
- #region 什么功用
- 单个人去做手机开发选什么平台好?android,iphone?解决办法
- 请教EDMA中的DRA(DMA Region Access)是如何分区的
- iphone app拖进iTunes生成ipa包出现embedded.mobileprovision异常
- !装完exchange SDK了,Exchange 2000 Sample Gateway code在哪里
- db2pd -db sample -transactions 没有内容显示
- tomcat没法部署项目报错 Exploded location overlaps an existing deployment
- weblogic调度新项目 set new Location 按钮无法点击
- weblogic部署新项目 set new Location 按钮无法点击解决办法
- 对于手机android iphone ipad 在线播放视频,服务器需要哪些要求呢?该怎么解决
- tomcat无法部署项目报错 Exploded location overlaps an existing deployment,该如何处理
- 用ghost还原win xp出现如下提示"output error file to the following location A:\Ghost TRR.TXT解决方法
- >>> PayPal mobile for Android / iPhone 开发包 开放啦!