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
- 浏览: 2539785 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
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 589ionic UI(5)UI and Backend 1 Pr ... -
Stanford Cource(2)Demo App Caculator
2014-06-24 01:29 897Stanford Cource(2)Demo App Ca ... -
Mono on MAC
2014-06-04 03:27 974Mono on MACJust fine the tool f ... -
IOS7 App Development Essentials(4)IPhone5, IPhone5s, IPhone5c
2014-04-11 03:59 981IOS7 App Development Essentia ... -
IOS7 App Development Essentials(3)NSUserDefaults
2014-04-11 02:58 1005IOS7 App Development Essentia ... -
IPhone and Location(1)Documents User Location
2013-10-18 03:50 1304IPhone and Location(1)Documents ... -
Learn Objective C(6)Programming with Objective-C - Working with Blocks and Deali
2013-10-18 00:02 924Learn Objective C(6)Programming ... -
Learn Objective C(5)Programming with Objective-C - Working with Protocols and Va
2013-10-17 23:47 996Learn Objective C(5)Programming ... -
Learn Objective C(4)Programming with Objective-C - Encapsulating Data and Custom
2013-10-17 23:23 934Learn Objective C(4)Programming ... -
Learn Objective C(3)Programming with Objective-C - Defining Classes, Working wit
2013-10-17 23:09 1014Learn Objective C(3)Programmi ... -
Learn Objective C(2)Learn Objective-C in Day 6 - 4 ~ 6
2013-10-17 00:30 960Learn Objective C(2)Learn Obj ... -
Learn Object C(1) Learn Objective-C in Day 6 - 1 ~ 3
2013-10-17 00:22 1110Learn Object C(1) Learn Objec ... -
APNS(4)Recall the Process and Learn Java APNS
2013-04-18 02:48 3466APNS(4)Recall the Process and L ... -
Build the iOS Things with J2Objc
2013-04-12 03:25 2462Build the iOS Things with J2Obj ... -
APNS(3)Write the Easy Client App
2013-01-15 07:23 1692APNS(3)Write the Easy Client Ap ... -
APNS(2)Try to Finish the first Example
2013-01-14 07:56 1537APNS(2)Try to Finish the first ... -
Stanford Cource(1)MVC and Object-C
2012-12-14 14:04 1317Stanford Cource(1)MVC and Objec ... -
Some VI Tips
2012-11-15 04:48 1093Some VI Tips Today, I need to c ... -
MAC Mini Setup
2012-09-25 18:45 1326MAC Mini Setup I am dealing wit ... -
Android Talker(1)MAC Environment
2012-09-01 00:16 1921Android 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 ...
《Learn iPhone and iPad Cocos2D Game Development》中文版是一本专为苹果移动平台开发者设计的游戏开发教程。Cocos2D是一款广泛使用的2D游戏引擎,尤其在iOS平台上备受青睐,因为它提供了强大的图形渲染能力、丰富...
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中文版全集》是学习cocos2d游戏开发的宝贵资源,无论你是初入游戏开发的新手,还是寻求提高的资深开发者,都能从中受益匪浅,掌握创建令人惊叹的iOS游戏所需...
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.
01 介绍cocos2d 02 开始学习 03 基础知识 04 你的第一个游戏 05 游戏构成要素 06 深入了解精灵 07 横向滚屏射击游戏 08 完成滚屏射击游戏 09 粒子效果 10 瓷砖地图基础知识 11 45度角瓷砖地图 ...13 弹球游戏
2. iOS外围传感器编程:描述中提及了“iOS外围传感器编程”,这说明书中将对如何访问和使用iPhone和iPad的内置传感器进行编程作出介绍。这可能包括加速度计、陀螺仪、磁力计等传感器的编程接口和方法。 3. ...
标题中的"Location-and-Map-Sample-master.zip_GPS"暗示了一个iOS开发相关的项目,它专注于获取设备的GPS(全球定位系统)位置,包括纬度和经度。这个项目可能是一个示例应用,展示了如何在iPhone SDK中集成GPS功能...
《学习iPhone and iPad cocos2d》是一份专为iOS设备开发者设计的学习资源,特别是针对使用cocos2d游戏引擎的初学者。cocos2d是一个开源的2D游戏开发框架,广泛应用于iPhone、iPad等iOS设备上的游戏和交互式应用开发...
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 ...
《Learn iPhone and iPad Cocos2D Game Development》是一本专为iOS游戏开发爱好者和专业人士编写的英文原版书籍,旨在帮助读者深入理解如何利用Cocos2D框架创建高性能、交互性强的游戏。Cocos2D是一个广泛使用的...
【标题】"iPhone Cocos2D游戏示例"是一份专为Cocos2D游戏初学者准备的宝贵资源。这个项目提供了一个实际的游戏样本,帮助新手理解如何在iOS平台上使用Cocos2D框架构建游戏。 【描述】"适用于Cocos2D游戏初学者的源...
iPhone SDK 3 Programming:Advanced Mobile Development for Apple iPhone and iPod touch,英文版本,大小 9 Mb,作者 Maher Ali,2009 年 9 月出版。 Get the expert guidance you need to begin building native...
It cuts through the fog of jargon and misinformation that surrounds iPhone and iPad app development, and gives you simple, step-by-step instructions to get you started. ☆ 出版信息:☆ [作者信息] ...
斯坦福大学的"Developing iOS 7 Apps for iPhone and iPad"课程是学习如何构建iOS应用程序的宝贵资源,尤其适合初学者和有经验的开发者。这门课程采用最新的Xcode 5作为开发环境,针对苹果公司的操作系统iOS 7进行...