iOS.Location-Based Service

來源:互聯網
上載者:User

標籤:

基於位置地區的服務1. 背景

Ref[1]

在iOS裝置鎖屏的狀態下,App的icon會出現在螢幕的左下角。

iOS 8 Feature: Location-based Lockscreen App Shortcuts Appearing on iPhone

http://www.igeeksblog.com/ios-8-feature-location-based-lockscreen-app-shortcuts-appearing-on-iphone/

Can I get my iOS app to appear on the lower left corner of the lock screen?

http://stackoverflow.com/questions/25897219/can-i-get-my-ios-app-to-appear-on-the-lower-left-corner-of-the-lock-screen

 

2. 地區監控和iBeacon

Ref[1] 

2.1 Core Location framework提供兩種方式來檢測(detect)一個使用者進入和退出某個地區:

A) geographical region monitoring (iOS 4.0+ OS X v10.8+)

B) beacon region monitoring (iOS 7+)

geographical region is an area defined by a circle of a specified radius around a known point on the Earth’s surface.

beacon  region is an area defined by the device’s proximity to Bluetooth low-energy beacons.

Apps can use region monitoring to be notified when a user crosses geographic boundaries or when

a user enters or exits the vicinity of a beacon.

In iOS, regions associated with your app are tracked at all times, including when the app isn’t running.

If a region boundary is crossed while an app isn’t running, that app is relaunched into the background to handle the event.

Similarly, if the app is suspended when the event occurs, it’s woken up and given a short amount of time (around 10 seconds)

to handle the event. 

 

2.2 判斷Region Monitoring(地區監控)是否可用

A) 裝置沒有必要的硬體來支援RM。

B) 使用者拒絕App的使用RM的授權。

C) 使用者在"設定"App中關閉了定位服務。

D) 使用者在"設定"App中關閉了"後台App重新整理"的功能。

E) 裝置在Airplane模式時不能啟動必須的硬體。

以上原因都會導致RM不可用。

在iOS 7.0+, 在監控地區之前調用isMonitoringAvailableForClass: and authorizationStatus(CLLocationManager)。

在之前的iOS中,調用regionMonitoringAvailable。

方法isMonitoringAvailableForClass:通過傳回值來告訴App硬體是否支援某類的RM。如果返回YES, 進而調用

authorizationStatus來決定App是否已被授權使用定位服務。如果status是kCLAuthorizationStatusAuthorized,

則App可以接收"穿越邊界"(boundary crossing)的通知。如果status是其它的值,則App不會收到這些通知。

"Finally, if your app needs to process location updates in the background, be sure to check the

backgroundRefreshStatus property of the UIApplication class. You can use the value of this property

to determine if doing so is possible and to warn the user if it is not. Note that the system doesn’t wake

your app for region notifications when the Background App Refresh setting is disabled globally

or specifically for your app." Ref[1]

 

2.3 監控地理地區 (Monitoring Geographical Regions)

Geographical region monitoring uses location services to detect entry and exit into known geographical locations.

2.3.1 定義一個被監控的地理地區

在監控地理地區之前,必須定義一個地區(region)並將它註冊到系統中。

iOS 7.0+, 使用CLCircularRegion類來定義。在以前的iOS版本中,使用CLRegion類。

每個region包括定義地理地區的資料和唯一的一個ID。這個ID用來在App中來標識一個地區。

使用CLLocationManager的方法startMonitoringForRegion: 來註冊地區。

Demo-1: Creating and registering a geographical region based on a Map Kit overlay

 

Monitoring of a geographical region begins immediately after registration for authorized apps.

However, don’t expect to receive an event right away, because only boundary crossings generate an event.

To check whether the user is already inside the boundary of a region, use the requestStateForRegion: method of the CLLocationManager class.

"Regions are a shared system resource, and the total number of regions available systemwide is limited.

For this reason, Core Location limits to 20 the number of regions that may be simultaneously monitored

by a single app. To work around this limit, consider registering only those regions in the user’s immediate vicinity.

As the user’s location changes, you can remove regions that are now farther way and add regions coming

up on the user’s path. If you attempt to register a region and space is unavailable, the location manager calls thelocationManager:monitoringDidFailForRegion:withError: method of its delegate with

thekCLErrorRegionMonitoringFailure error code."

2.3.2 處理穿越地理地區邊界的事件
  • locationManager:didEnterRegion:

  • locationManager:didExitRegion:

3. 監控Beacon地區

beacon由以下資訊標識:

proximity UUID: a 128-bit value that uniquely identifies one or more beacons as a certain type or from a certain organization.

major value: is a 16-bit unsigned integer that can be used to group related beacons that have the same proximity UUID.

minor value: is a 16-bit unsigned integer that differentiates beacons with the same proximity UUID and major value.

一個beacon地區可以代表多個beacon。

(Note that although every beacon must advertise a proximity UUID, major and minor values are optional.)

3.1 定義被監控的beacon地區

定義beacon地區使用CLBeaconRegion類。

"Note that a region’s identifier is unrelated to the identifying information that a beacon advertises."

Demo-2: Creating and registering a beacon region

 

"When a user’s device detects a beacon that is advertising the identifying information defined by

the registered beacon region (proximity UUID, major value, and minor value), the system generates

an appropriate region event for your app." 

3.2 處理Beacon地區的穿越邊界事件3.3 Determining the Proximity of a Beacon Using Ranging

startRangingBeaconsInRegion:

Demo-3: Determining the relative distance between a beacon and a device

 

4. 將iOS裝置轉換為iBeacon

Ref[1]

"Any iOS device that supports sharing data using Bluetooth low energy can be used as an iBeacon.

In Core Bluetooth, a peripheral is a device that advertises and shares data using Bluetooth low energy. Advertising your beacon’s data is the only way other devices can detect and range your beacon. " Ref[1]

 

 

Reference

1. <<Location and Maps Programming Guide>> Region Monitoring and iBeacon

https://developer.apple.com/library/mac/documentation/UserExperience/Conceptual/LocationAwarenessPG/RegionMonitoring/RegionMonitoring.html

2. iOS 8 pushes location context to a new level: lock screen notifications triggered by iBeacon

http://blog.estimote.com/post/97824495825/ios-8-pushes-location-context-to-a-new-level-lock

3. Core Bluetooth Programming Guide 

 

Item

Region Monitoring: 地區監控,RM

iOS.Location-Based Service

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.