iBeacon‚’½£¦‚ˆ†ï¼°—軽«½ˆ‚‹è‘è·‌離ç„ç·é€

  • View
    9.875

  • Download
    0

Embed Size (px)

DESCRIPTION

iBeaconでできること – Developers.IO Meetup 02 の発表資料です。 http://dev.classmethod.jp/news/developersio-meetup-02/ iBeaconの実装方法をデモも交えて出来る限り分かりやすく解説しました。 また、iBeaconを使う上での注意すべきTipsもご紹介しています。

Text of iBeacon‚’½£¦‚ˆ†ï¼°—軽«½ˆ‚‹è‘è·‌離ç„ç·é€...

  • iBeacon ! underscore Inc.!
  • underscore Inc. (classmethod)! iOS / Android & & & & & & & ! Objective-C, Java, Ruby, ...
  • iBeacon iBeacon ! () iBeacon!
  • iBeacon Beacon! Beacon Estimote iPhone Mac 2!
  • 1 iBeacon! ! ! 2 Beacon! 3 ! 4
  • 1 iBeacon
  • iBeacon Beacon(Region) !
  • iBeacon (Ranging) Beacon1 A B
  • Region Beacon Beacon Beacon
  • Xcode 5! iOS SDK 7! CoreLocation.framework
  • if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) { ! // CLLocationManager self.manager = [CLLocationManager new]; self.manager.delegate = self; ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; ! // CLBeaconRegion self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID identifier:@"jp.classmethod.testregion"]; ! // iBeacon [self.manager startMonitoringForRegion:self.region]; }
  • iBeacon if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) { ! // CLLocationManager self.manager = [CLLocationManager new]; self.manager.delegate = self; ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; ! // CLBeaconRegion self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID identifier:@"jp.classmethod.testregion"]; ! // iBeacon [self.manager startMonitoringForRegion:self.region]; }
  • iBeacon if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) { ! // CLLocationManager self.manager = [CLLocationManager new]; self.manager.delegate = self; ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; ! // CLBeaconRegion self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID identifier:@"jp.classmethod.testregion"]; ! // iBeacon [self.manager startMonitoringForRegion:self.region]; }
  • iBeacon if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]]) { ! // CLLocationManager self.manager = [CLLocationManager new]; self.manager.delegate = self; ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; ! // CLBeaconRegion self.region = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID identifier:@"jp.classmethod.testregion"]; ! // iBeacon [self.manager startMonitoringForRegion:self.region]; }
  • CLLocationManagerDelegate - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { } ! - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { }
  • CLLocationManagerDelegate - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { } ! - (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region { } Exit201! ()
  • Exit
  • - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { [self.manager startRangingBeaconsInRegion:self.region]; }
  • - (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region { [self.manager startRangingBeaconsInRegion:self.region]; } !
  • - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { CLBeacon *beacon = beacons.firstObject; switch (beacon.proximity) { case CLProximityUnknown: NSLog(@"CLProximityUnknown"); break; case CLProximityImmediate: NSLog(@"CLProximityImmediate"); break; case CLProximityNear: NSLog(@"CLProximityNear"); break; case CLProximityFar: NSLog(@"CLProximityFar"); break; } }
  • - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region { CLBeacon *beacon = beacons.firstObject; switch (beacon.proximity) { case CLProximityUnknown: NSLog(@"CLProximityUnknown"); break; case CLProximityImmediate: NSLog(@"CLProximityImmediate"); break; case CLProximityNear: NSLog(@"CLProximityNear"); break; case CLProximityFar: NSLog(@"CLProximityFar"); break; } } ! Beacon!
  • Beacon
  • Beacon proximityUUID double Region major NSNumber Beacon minor NSNumber Beacon proximity CLProximity accuracy double rssi NSInteger
  • https://github.com/ suwa-yuki/ BeaconSample
  • 2 Beacon
  • Beacon A UUID = XXXX-...! major = 1! minor = 1 B UUID = XXXX-...! major = 1! minor = 2
  • Beacon A UUID = XXXX-...! major = 1! minor = 1 B UUID = XXXX-...! 16! major = 1! 065,535 minor = 2
  • Xcode 5! iOS SDK 7! CoreLocation.framework! CoreBluetooth.framework
  • Beacon - (void)viewDidLoad { [super viewDidLoad]; ! ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; // CBPeripheralManager self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil]; // if (self.peripheralManager.state == CBPeripheralManagerStatePoweredOn) { [self startAdvertising]; } }
  • Beacon - (void)viewDidLoad { [super viewDidLoad]; ! ! // UUIDNSUUID NSString *uuid = @"41282F26-524C-4F16-9E95-C06D90AF942A"; self.proximityUUID = [[NSUUID alloc] initWithUUIDString:uuid]; // CBPeripheralManager self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil options:nil]; // if (self.peripheralManager.state == CBPeripheralManagerStatePoweredOn) { [self startAdvertising]; } }
  • Beacon - (void)startAdvertising { // CLBeaconRegion ! CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID major:1 minor:2 identifier:@"jp.classmethod.testregion"]; // NSDictionary NSDictionary *beaconPeripheralData = [beaconRegion peripheralDataWithMeasuredPower:nil]; // [self.peripheralManager startAdvertising:beaconPeripheralData]; }
  • Beacon - (void)startAdvertising { // CLBeaconRegion ! Beacon CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID major:1 minor:2 identifier:@"jp.classmethod.testregion"]; // NSDictionary NSDictionary *beaconPeripheralData = [beaconRegion peripheralDataWithMeasuredPower:nil]; // [self.peripheralManager startAdvertising:beaconPeripheralData]; }
  • Beacon - (void)startAdvertising { // CLBeaconRegion ! Beacon CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:self.proximityUUID major:1 minor:2 identifier:@"jp.classmethod.testregion"]; // NSDictionary NSDictionary *beaconPeripheralData = [beaconRegion peripheralDataWithMeasuredPower:nil]; // [self.peripheralManager startAdvertising:beaconPeripheralData]; } (rssi)!
  • 1 Beacon
  • Beacon
  • https://github.com/ suwa-yuki/ BeaconSample
  • 3
  • () Beacon didEnterRegion: [self.manager requestStateForRegion:self.region];
  • - (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region { switch (state) { case CLRegionStateInside: NSLog(@"CLRegionStateInside"); // break; case CLRegionStateOutside: NSLog(@"CLRegionStateOutside"); // break; case CLRegionStateUnknown: NSLog(@"CLRegionStateUnknown"); break; default: break; } }