iBeacon使用两个iOS设备—一个StartAvertising和一个startMonitoringForRegion

iBeacon使用两个iOS设备—一个StartAvertising和一个startMonitoringForRegion,ios,ios7,Ios,Ios7,更新:找到了,然后我可以从Android设备上找到iOS信标,但应用商店上的任何应用(搜索定位信标)都找不到该信标。iOS 9有问题吗 我试着用一个设备做广告,一个设备做监控。 我原以为会调用“didEnterRegion”,但什么都没有-你知道为什么吗 项目1:广告代码: ViewController.h fil #import <UIKit/UIKit.h> @import CoreBluetooth; @interface ViewController : UIViewCon

更新:找到了,然后我可以从Android设备上找到iOS信标,但应用商店上的任何应用(搜索定位信标)都找不到该信标。iOS 9有问题吗

我试着用一个设备做广告,一个设备做监控。 我原以为会调用
“didEnterRegion”
,但什么都没有-你知道为什么吗

项目1:广告代码:

ViewController.h fil

#import <UIKit/UIKit.h>
@import CoreBluetooth;

@interface ViewController : UIViewController <CBPeripheralManagerDelegate>

@property (strong, nonatomic) CBPeripheralManager *peripheralManager;

@end

您有权查找(
CLLocationManager
part)吗?谢谢,是的,我有权查找。您有权查找(
CLLocationManager
part)吗?谢谢,是的,我有权查找。
//
//  ViewController.m
//  MyBeacon
//
//


// 17BEFCE4-43B9-4921-BDAA-8361A24727A9

#import "ViewController.h"
// #import <CoreBluetooth/CoreBluetooth.h>
@import CoreLocation;
@import CoreBluetooth;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.


    NSUUID *proximityUUID = [[NSUUID alloc]
                             initWithUUIDString:@"39ED98FF-2900-441A-802F-9C398FC199D2"];

    // Create the beacon region.
    CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc]
                                    initWithProximityUUID:proximityUUID
                                    identifier:@"com.mycompany.myregion"];

    // Create a dictionary of advertisement data.
    NSDictionary *beaconPeripheralData =
    [beaconRegion peripheralDataWithMeasuredPower:nil];

    // Create the peripheral manager.
    CBPeripheralManager *peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self queue:nil];

    self.peripheralManager = peripheralManager;

    // Start advertising your beacon's data.
    [self.peripheralManager startAdvertising:beaconPeripheralData];
}

- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
//
//  ViewController.h
//  UseMyBeacon
//
//

#import <UIKit/UIKit.h>

@import CoreLocation;

@interface ViewController : UIViewController <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *locationManager;
@property (strong, nonatomic) CLBeaconRegion *region;

@end
//
//  ViewController.m
//  UseMyBeacon
//
//

#import "ViewController.h"

@import CoreLocation;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;


    NSUUID *proximityUUID = [[NSUUID alloc]initWithUUIDString:@"39ED98FF-2900-441A-802F-9C398FC199D2"];

    CLBeaconRegion *thisRegion = [[CLBeaconRegion alloc] initWithProximityUUID:proximityUUID identifier:@"com.mycompany.myregion"];

    self.region = thisRegion;

    Boolean b = [CLLocationManager isMonitoringAvailableForClass:[thisRegion class]];

    if (b) {
        // Create the beacon region to be monitored.
        //        CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc]
        //                                        initWithProximityUUID:proximityUUID
        //                                        identifier:identifier];

        // Register the beacon region with the location manager.

        self.locationManager.delegate = self;

        [self.locationManager startMonitoringForRegion:thisRegion];
    }
}

- (void)locationManager:(CLLocationManager *)manager
         didEnterRegion:(CLRegion *)region{

}

- (void) locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{
    [self.locationManager requestStateForRegion:self.region];
}

- (void)locationManager:(CLLocationManager *)manager
rangingBeaconsDidFailForRegion:(CLBeaconRegion *)region
              withError:(NSError *)error{

}

- (void)locationManager:(CLLocationManager *)manager
       didFailWithError:(NSError *)error{

}

- (void) locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region
{
    switch (state) {
        case CLRegionStateInside:
            [self.locationManager startRangingBeaconsInRegion:self.region];

            break;
        case CLRegionStateOutside:
        case CLRegionStateUnknown:
        default:
            // stop ranging beacons, etc
            NSLog(@"Region unknown");
    }
}

- (void) locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
    if ([beacons count] > 0) {
        // Handle your found beacons here
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end