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
- 浏览: 2486398 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
发表评论
-
ionic UI(5)UI and Backend
2016-12-02 03:22 563ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 864Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 944Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 941IOS7 App Development Essentia ... -
IOS7 App Development Essentials(3)NSUserDefaults
2014-04-11 02:58 966IOS7 App Development Essentia ... -
IPhone and Location(1)Documents User Location
2013-10-18 03:50 1277IPhone and Location(1)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 893Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 966Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 906Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 990Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 924Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1074Learn Object C(1) Learn Objec ... -
APNS(4)Recall the Process and Learn Java APNS
2013-04-18 02:48 3429APNS(4)Recall the Process and L ... -
Build the iOS Things with J2Objc
2013-04-12 03:25 2431Build the iOS Things with J2Obj ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1607APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1499APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1264Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1060Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1284MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1891Android Talker(1)MAC Environmen ...
相关推荐
A Learner’s Guide to Creating Objective-C Applications for the iPhone and iPad Book Description : Let’s say you have a killer app idea for iPhone and iPad. Where do you begin? Head First iPhone and...
iOS 10 SDK Development: Creating iPhone and iPad Apps with Swift by Chris Adamson English | 24 Mar. 2017 | ASIN: B071RRCK9R | 264 Pages | AZW3 | 5.24 MB All in on Swift! iOS 10 and Xcode 8 make it ...
By creating 2-3 sample games over the course of the book, you’ll learn key concepts of the cocos2d game engine and relevant tools like Zwoptex (TextureAtlas), ParticleDesigner (Particle Effects), ...
Learn iPhone and iPad cocos2d Game Development中文版全集
《Learn iPhone and iPad Cocos2D Game Development》翻译的章节。 来至cocoaChina论坛会员提供 个人觉得是一本不错的教程
Head First iPhone and iPad Development, 2nd Edition.pdf
One iPhone app example. Use image-controller, pumkinFace mask, and transitions in it. run on the iPhone SDK. not iPhone.
This book is intended for IT staff members that will be charged with planning an iPhone and ipad implementation or pilot program, as well as those that will be charged with ultimately deploying and ...
the iPhone and iPad are “...some of the coolest, most powerful, and most technologically advanced tools ever made—period!” He is fascinated by the fact that, just under the appealing touch screen ...
Head First iPhone and iPad Development will help you get your first application up and running in no time. You'll not only learn how to design for Apple's devices, you'll also master the iPhone SDK ...
01 介绍cocos2d 02 开始学习 03 基础知识 04 你的第一个游戏 05 游戏构成要素 06 深入了解精灵 07 横向滚屏射击游戏 08 完成滚屏射击游戏 09 粒子效果 10 瓷砖地图基础知识 11 45度角瓷砖地图 ...13 弹球游戏
learn iphone and ipad cocos2d
Developing iOS 7 Apps for iPhone and iPad ppt (1-10) 最新 xcode 5的 斯坦福 ios 公开课 ppt
Building iPhone and iPad Electronic Projects。关于iOS外围传感器编程
learn iphone and ipad cocos2d game development 源码2
中文Learn iPhone and iPad cocos2d Game Development.pdf
Along the way, he introduces techniques and sample code designed to streamline development, eliminate complexity, optimize performance, and leverage all iPhone’s native capabilities—from its ...