Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/118.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios iBeacon和通知_Ios_Objective C_Ibeacon - Fatal编程技术网

Ios iBeacon和通知

Ios iBeacon和通知,ios,objective-c,ibeacon,Ios,Objective C,Ibeacon,我正在开发一个iOS应用程序,我正在使用信标 我有个问题。我正处于开发的开始阶段,所以我只有我的appdelegate。在appdelegate.m中,我已经这样初始化了 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[U

我正在开发一个iOS应用程序,我正在使用信标

我有个问题。我正处于开发的开始阶段,所以我只有我的appdelegate。在appdelegate.m中,我已经这样初始化了

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

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

    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"8AEFB031-6C32-486F-825B-E26FA193487D"];
    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                                identifier:@"Region"];

    if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
    {
        NSLog(@"I'm looking for a beacon");
        [self.locationManager startRangingBeaconsInRegion:region];
    } else {
        NSLog(@"Device doesn't support beacons ranging");
    }

    return YES;
}
然后我写了两个委托方法

- (void) locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    NSLog(@"EXIT");
}

- (void) locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"ENTER");
}

但是他们从来没有接到过电话!!!这里有什么问题

您可以设置范围,但从不监视区域

信标测距将只调用:
locationManager:didRangeBeacons:inRegion:

您想要的enterRegion/exitRegion方法仅用于监视。所以说:

-(void)startMonitoringForRegion:(CLRegion*)region

我不知道为什么没有呼叫,但这就是我们处理信标的方法

- (void)createBeaconRegion
{
    self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"8AEFB031-6C32-486F-825B-E26FA193487D"];
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                            identifier:@"Region"];

if ([CLLocationManager isMonitoringAvailableForClass:[CLBeaconRegion class]])
{
    NSLog(@"I'm looking for a beacon");
    [self.locationManager startRangingBeaconsInRegion:region];
} else {
    NSLog(@"Device doesn't support beacons ranging");
}
}

- (void)turnOnRanging
{
    NSLog(@"Turning on ranging...");

    if (![CLLocationManager isRangingAvailable]) {
        NSLog(@"Couldn't turn on ranging: Ranging is not available.");
        self.rangingSwitch.on = NO;
        return;
    }

    if (self.locationManager.rangedRegions.count > 0) {
        NSLog(@"Didn't turn on ranging: Ranging already on.");
        return;
    }

    [self createBeaconRegion];
    [self.locationManager startRangingBeaconsInRegion:self.beaconRegion];

    NSLog(@"Ranging turned on for region: %@.", self.beaconRegion);
}


- (void)startRangingForBeacons
{
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;

    self.detectedBeacons = [NSArray array];

    [self turnOnRanging];
}

- (void)stopRangingForBeacons
{
    if (self.locationManager.rangedRegions.count == 0) {
        NSLog(@"Didn't turn off ranging: Ranging already off.");
        return;
    }

    [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
 NSLog(@"Turned off ranging.");
}
您可以使用下面的链接引用整个示例项目

用来显示信标的

希望它能帮助你