{"id":263350,"date":"2015-08-11T20:40:02","date_gmt":"2015-08-11T16:40:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=263350"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=263350","title":{"rendered":"\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0435\u0439 iBeacon \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Swift"},"content":{"rendered":"<p>     \t\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Bluetooth \u043c\u0430\u044f\u0447\u043a\u043e\u0432 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442 \u0447\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445, \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432 \u043c\u0443\u0437\u0435\u0439\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430\u0445, \u043c\u044b \u0432 Techmas \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0445 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c, \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043d\u0438\u0436\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 SDK \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u044f\u0447\u043a\u0430\u043c\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e Swift \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 CoreLocation \u0438 CoreBluetooth.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e1e\/689\/54d\/e1e68954d01b4522bbe8a74541671b7d.png\"\/><\/p>\n<p>  <a name=\"habracut\"><\/a><\/p>\n<p>  <img decoding=\"async\" align=\"left\" src=\"https:\/\/habrastorage.org\/files\/7c4\/449\/a99\/7c4449a996de49da97e5f8522027a932.jpg\"\/><br \/>  \u041d\u0430\u0447\u043d\u0435\u043c \u0441 \u0442\u0435\u043e\u0440\u0438\u0438 \u043f\u043e \u0441\u0430\u043c\u043e\u0439 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438. \u0412 \u043a\u043e\u043d\u0446\u0435 2014 \u0433\u043e\u0434\u0430 Bluetooth Special Interest Group (SIG) \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e Bluetooth v4.2 (Bluetooth Low Energy, BLE). <\/p>\n<p>  \u0421\u043b\u0435\u0434\u0443\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e, \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u043c \u0432 31 \u0431\u0430\u0439\u0442 \u0432 \u0432\u0438\u0434\u0435 \u043f\u0430\u043a\u0435\u0442\u0430 Scan Response Data. \u042d\u0442\u043e\u0442 \u043f\u0430\u043a\u0435\u0442 \u0434\u0435\u043b\u0438\u0442\u0441\u044f \u043d\u0430 \u0442\u0430\u043a \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u043c\u044b\u0435 AD \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0431\u043e\u0439 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0431\u0430\u0439\u0442\u043e\u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043f\u0440\u0435\u0434\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u0437\u043c\u0435\u0440\u043e\u0432. \u041f\u0440\u0438\u043d\u0438\u043c\u0430\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e 16 \u0431\u0430\u0439\u0442 \u0438\u0437 \u044d\u0442\u043e\u0433\u043e \u043f\u0430\u043a\u0435\u0442\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0443\u0445\u043e\u0434\u0438\u0442\u044c \u043d\u0430 128 \u0431\u0438\u0442\u043d\u044b\u0439 UUID \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u0431\u043e\u043b\u044c\u0448\u043e\u0435 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0441 \u043e\u0434\u043d\u043e\u0433\u043e \u043c\u0430\u044f\u0447\u043a\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f. <\/p>\n<p>  \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442 iBeacon \u0431\u044b\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0435\u0439 Apple \u0432 2013 \u0433\u043e\u0434\u0443. \u0412 \u043d\u0435\u043c \u0441\u0438\u0433\u043d\u0430\u043b BLE \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 MAC \u0430\u0434\u0440\u0435\u0441 \u0438 \u0434\u0432\u0435 AD \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b. \u0422\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u043f\u0435\u0440\u0432\u0430\u044f AD \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0449\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e, \u0432\u0442\u043e\u0440\u0430\u044f \u0438\u043c\u0435\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u0435 \u043a iBeacon. \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435. <\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u0439 \u0431\u0430\u0439\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0434\u043b\u0438\u043d\u0435 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0432 26 \u0431\u0430\u0439\u0442 (0x1A), \u0441\u043b\u0435\u0434\u043e\u043c \u043e\u0434\u0438\u043d \u0431\u0430\u0439\u0442 \u043d\u0430 \u0442\u0438\u043f, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043a \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044e. \u0414\u0430\u043b\u0435\u0435 \u0438\u0434\u0435\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 Apple (0xFF). \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0434\u0432\u0430 \u0431\u0430\u0439\u0442\u0430 \u043d\u0430 \u0438\u043d\u0434\u0438\u043a\u0430\u0442\u043e\u0440\u044b \u043c\u0430\u044f\u0447\u043a\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0440\u0430\u0432\u043d\u044b 0x02 \u0438 0x15 (\u043f\u043e \u043e\u0434\u043d\u043e\u043c\u0443 \u0431\u0430\u0439\u0442\u0443 \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439). \u041a\u0430\u043a \u043c\u044b \u043f\u0438\u0441\u0430\u043b\u0438 \u0432\u044b\u0448\u0435, \u043d\u0430 UUID \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u0443\u0445\u043e\u0434\u0438\u0442 16 \u0431\u0430\u0439\u0442. \u0418\u0442\u043e\u0433\u043e \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 Major \u0438 Minor \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u0435\u0433\u043e \u043f\u043e 2 \u0431\u0430\u0439\u0442\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435 \u043f\u043e\u043b\u0435 TX Power \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u043a\u0430\u043b\u0438\u0431\u0440\u043e\u0432\u043a\u0438 \u043c\u0430\u044f\u0447\u043a\u0430 (1 \u0431\u0430\u0439\u0442). <\/p>\n<p>  \u041e\u0431\u0449\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u043f\u0430\u043a\u0435\u0442\u0430:<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/c71\/65a\/7cf\/c7165a7cf2f44d3b8e51555fa6ad107b.png\"\/><\/p>\n<p>  \u0418\u0437\u0443\u0447\u0438\u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u043e\u043d\u044f\u0442\u0438\u044f, \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a SDK \u043e\u0442 Apple \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u044f\u0447\u043a\u0430\u043c\u0438 \u0438 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u043c\u0430\u044f\u0447\u043a\u0435. <\/p>\n<p>  \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0438 \u043c\u0430\u044f\u0447\u043a\u0438, \u043a\u0443\u043f\u043b\u0435\u043d\u043d\u044b\u0435 <a href=\"http:\/\/www.alibaba.com\/product-detail\/IOS-Android-UUID-Programmable-Bluetooth-Beacon_1909840654.html\">\u0437\u0434\u0435\u0441\u044c<\/a>:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/a95\/5de\/81f\/a955de81f892461b8d284bfd97c15dc6.png\"\/><\/p>\n<p>  \u041a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u043e\u0436\u043d\u043e \u0432\u0437\u044f\u0442\u044c \u0432 <a href=\"https:\/\/github.com\/barsuga\/techbeacon\">Github<\/a>.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a: <\/p>\n<pre><code>import UIKit import CoreLocation import CoreBluetooth <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435, \u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0441\u043a\u0430\u0436\u0435\u043c \u043f\u043e\u0437\u0436\u0435.   <\/p>\n<pre><code>var locationManager = CLLocationManager() var region = CLBeaconRegion() <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u044b, \u043c\u044b \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 <i>viewDidLoad()<\/i>. \u0412 \u043d\u0435\u043c \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c:   <\/p>\n<pre><code>override func viewDidLoad() {      super.viewDidLoad()      locationManager.delegate = self } <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442 <i>region<\/i> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442 \u043e\u0431\u043b\u0430\u0441\u0442\u044c \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0430\u044f\u0447\u043a\u043e\u0432 \u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0435\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0438\u0442\u044c \u043f\u043e \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c \u043c\u0430\u044f\u0447\u043a\u043e\u0432: <i>uuid<\/i>, \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u043f\u043e\u043b\u0435\u0439 <i>major<\/i> \u0438 <i>minor<\/i>.<\/p>\n<pre><code>let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: &quot;E2C56DB5-DFFB-48D2-B060-D0F5A71096E0&quot;), identifier: &quot;ru.techmas.techbeacon&quot;)  <\/code><\/pre>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 <i>locationManager<\/i>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0443 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0430\u044f\u0447\u043a\u043e\u0432 \u0438 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0445 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0438\u0442\u044c \u043d\u0430\u0448 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u043b\u0435\u0440 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u043e\u043c <i>locationManager<\/i>: <\/p>\n<pre><code>class ViewController: UIViewController, CLLocationManagerDelegate { <\/code><\/pre>\n<p>  \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 iOS 8 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0442\u044c \u0430\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u0439 \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438. \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b <i>locationManager.requestWhenInUseAuthorization()<\/i> \u0438 <i>locationManager.requestAlwaysAuthorization()<\/i>. \u041e\u043d\u0438 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0432\u044b\u0439 \u0434\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0433\u0435\u043e\u043b\u043e\u043a\u0430\u0446\u0438\u0438 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u043c \u043e\u043a\u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0442\u043e\u0433\u0434\u0430 \u043a\u0430\u043a \u0432\u0442\u043e\u0440\u043e\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f \u0432 \u043b\u044e\u0431\u043e\u0435 \u0432\u0440\u0435\u043c\u044f. <\/p>\n<p>  \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0432 info.plist, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u0432 \u0434\u0438\u0440\u0435\u043a\u0442\u043e\u0440\u0438\u0438 \u00abSupporting Files\u00bb: <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/8c0\/f64\/402\/8c0f64402df541fba66d5f53b9994d77.png\"\/><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0435\u0434\u0443\u043f\u0440\u0435\u0436\u0434\u0435\u043d\u0438\u0435 \u043d\u0435 \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u043b\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <i>authorizationStatus()<\/i> \u043a\u043b\u0430\u0441\u0441\u0430 <i>CLLocationManager<\/i>:<\/p>\n<pre><code>if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse) {      locationManager.requestWhenInUseAuthorization() }  <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043a \u043f\u043e\u0438\u0441\u043a\u0443 \u043c\u0430\u044f\u0447\u043a\u043e\u0432! <\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u043e\u0438\u0441\u043a\u0430:   <\/p>\n<pre><code>locationManager.startRangingBeaconsInRegion(region) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043d\u0430\u0439\u0434\u0435\u043d\u043d\u044b\u0445 \u043c\u0430\u044f\u0447\u043a\u0430\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043d\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:   <\/p>\n<pre><code>func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) { } <\/code><\/pre>\n<p>  \u0412\u043d\u0443\u0442\u0440\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u0434\u0435\u043b\u0435\u0433\u0430\u0442\u0430 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u0430\u044f\u0447\u043a\u0430\u043c, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0448\u0435\u043b \u043d\u0430\u0448 <i>locationManager<\/i>. \u0414\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u043d\u0438\u0445 \u0432 \u043a\u043e\u043d\u0441\u043e\u043b\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u043e\u043a\u0443:   <\/p>\n<pre><code>println(beacons) <\/code><\/pre>\n<p>  \u041f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u043c\u0430\u044f\u0447\u043a\u0435 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. <\/p>\n<p>  \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0438\u0439 \u043c\u0430\u044f\u0447\u043e\u043a:   <\/p>\n<pre><code>let knownBeacons = beacons.filter{ $0.proximity != CLProximity.Unknown } if (knownBeacons.count &gt; 0) {             let closestBeacon = knownBeacons[0] as! CLBeacon } <\/code><\/pre>\n<p>  \u041e\u0431\u044a\u0435\u043a\u0442 <i>closestBeacon<\/i> \u0438\u043c\u0435\u0435\u0442 \u043f\u043e\u043b\u044f, \u043e \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u0432\u044b\u0448\u0435:   <\/p>\n<ul>\n<li>major<\/li>\n<li>minor<\/li>\n<li>proximity<\/li>\n<li>rssi<\/li>\n<li>accuracy<\/li>\n<\/ul>\n<p>  \u041e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c\u0441\u044f \u043d\u0430 \u043f\u043e\u043b\u0435 <i>proximity<\/i>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0438\u043c\u0435\u0435\u0442 \u0442\u0438\u043f enum. \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0432\u0438\u0434\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e:   <\/p>\n<pre><code>var proximityString = String() switch proximity { case .Near:     proximityString = &quot;\u0411\u043b\u0438\u0437\u043a\u043e&quot; case .Immediate:     proximityString = &quot;\u041d\u0435\u0434\u0430\u043b\u0435\u043a\u043e&quot; case .Far:     proximityString = &quot;\u0414\u0430\u043b\u0435\u043a\u043e&quot; case .Unknown:     proximityString = &quot;Unknown&quot; } <\/code><\/pre>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. \u041a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a:   <\/p>\n<pre><code>func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!) {         println(beacons)                  let knownBeacons = beacons.filter{ $0.proximity != CLProximity.Unknown }                  if (knownBeacons.count &gt; 0) {             let closestBeacon = knownBeacons[0] as! CLBeacon              major_label.text = String(stringInterpolationSegment: closestBeacon.major)             minor_label.text = String(stringInterpolationSegment: closestBeacon.minor)                          let proximity = closestBeacon.proximity                          var proximityString = String()                          switch proximity             {             case .Near:                 proximityString = &quot;\u0411\u043b\u0438\u0437\u043a\u043e&quot;             case .Immediate:                 proximityString = &quot;\u041d\u0435\u0434\u0430\u043b\u0435\u043a\u043e&quot;             case .Far:                 proximityString = &quot;\u0414\u0430\u043b\u0435\u043a\u043e&quot;             case .Unknown:                 proximityString = &quot;Unknown&quot;             }              proximity_label.text = proximityString             rssi_label.text = String(closestBeacon.rssi)             accuracy_label.text = String(stringInterpolationSegment: closestBeacon.accuracy)         }          }  <\/code><\/pre>\n<p>  \u041d\u0430\u0448\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0432\u0438\u0434: <br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/060\/f52\/a13\/060f52a1339d41ccb8f128d8159ec11c.png\"\/><\/p>\n<p>  \u041d\u0430\u0434\u0435\u0435\u043c\u0441\u044f, \u0447\u0442\u043e \u043d\u0430\u0448\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0432 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438 iBeacon \u0438 \u043d\u0430\u0447\u0430\u0442\u044c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u0412 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u044c\u044f\u0445 \u043c\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u043a \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u0439 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0431\u043e\u0440\u0430 \u043c\u0430\u044f\u0447\u043a\u043e\u0432, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u044f \u043f\u0440\u0438 \u043f\u043e\u043f\u0430\u0434\u0430\u043d\u0438\u0438 \u0432 \u0437\u043e\u043d\u0443 \u0441\u0438\u0433\u043d\u0430\u043b\u0430 \u0438 \u043c\u043d\u043e\u0433\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435.     \t<\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/264561\/\"> http:\/\/habrahabr.ru\/post\/264561\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>     \t\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0432\u043e\u0437\u0440\u0430\u0441\u0442\u0430\u044e\u0449\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441 \u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e Bluetooth \u043c\u0430\u044f\u0447\u043a\u043e\u0432 \u0432 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043e\u0431\u043b\u0430\u0441\u0442\u044f\u0445 \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u043e\u0442 \u0447\u0438\u043f\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0436\u0438\u0432\u043e\u0442\u043d\u044b\u0445, \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438 \u0432 \u043c\u0443\u0437\u0435\u0439\u043d\u043e\u0439 \u044d\u043a\u0441\u043f\u043e\u0437\u0438\u0446\u0438\u0438 \u0438 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0432\u043e\u0441\u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0435\u0439 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0439 \u043f\u043e \u0430\u043a\u0446\u0438\u044f\u043c \u0432 \u043c\u0430\u0433\u0430\u0437\u0438\u043d\u0430\u0445, \u043c\u044b \u0432 Techmas \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u043b\u0438 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0438\u0445 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043a\u043e\u043c\u0443-\u043d\u0438\u0431\u0443\u0434\u044c \u0438\u0437 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432, \u043a\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0441\u0432\u043e\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438 \u0435\u0449\u0435 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0430\u0442\u044c, \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043d\u0438\u0436\u0435 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u043c\u0438 \u043f\u043e\u043d\u044f\u0442\u0438\u044f\u043c\u0438 \u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044f\u043c\u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u0438. \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443\u0436\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043d\u0430\u0431\u043e\u0440 SDK \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043c\u0430\u044f\u0447\u043a\u0430\u043c\u0438, \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0442\u043e\u043b\u044c\u043a\u043e Swift \u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 CoreLocation \u0438 CoreBluetooth.<\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/e1e\/689\/54d\/e1e68954d01b4522bbe8a74541671b7d.png\"\/><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-263350","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/263350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=263350"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/263350\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=263350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=263350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=263350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}