So Scannen Sie mehrere Regionen mit startMonitoringForRegion in Objective-C

Habe ich seit über zwei tutorials Lesen und bin bis auf basic C. Lernen am besten durch tun und geschrieben haben, ein paar Licht-apps in der vergangenen Woche oder so. Bin immer up-to-speed zu schreiben, einige apps nutzen ibeacon. Wie werde ich durch einige Proben und Lesen Sie die Anleitung, die ich sehen, dass mehrere Regionen gescannt werden kann, durch ausführen startMonitoringForRegion für jede UUID. OK, so dass ich vermute, ich könnte führen Sie es einfach für jede UUID aber das funktioniert nicht. Ich bin sicher, ich mache etwas grundlegendes völlig falsch... der code unten ist ein totaler hack - sobald ich die Semantik werde ich ziehen die UUIDs aus einer DB mit einem API-Aufruf und als Schleife durch Sie aktivieren die überwachung. Der folgende code ergibt in der letzten Schleife und zeigt nur zwei der vier UUIDs.

in der Kopfzeile:

@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion2;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion3;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion4;

in main:

NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"86E4BDEA-C6FF-442C-95CB-E6E557A23CF2"];
self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.appcoda.testregion"];

NSUUID *uuid2 = [[NSUUID alloc] initWithUUIDString:@"C9AFF296-A722-4F2D-8669-47B7CCC79A14"];
self.myBeaconRegion2 = [[CLBeaconRegion alloc] initWithProximityUUID:uuid2 identifier:@"com.appcoda.testregion"];

NSUUID *uuid3 = [[NSUUID alloc] initWithUUIDString:@"1DBDDC7C-49BB-48BF-A2F6-A4825BD514EA"];
self.myBeaconRegion3 = [[CLBeaconRegion alloc] initWithProximityUUID:uuid3 identifier:@"com.appcoda.testregion"];

NSUUID *uuid4 = [[NSUUID alloc] initWithUUIDString:@"8D942B9E-0197-4C81-8722-92144599E9F7"];
self.myBeaconRegion4 = [[CLBeaconRegion alloc] initWithProximityUUID:uuid4 identifier:@"com.appcoda.testregion"];

[self.locationManager startMonitoringForRegion:self.myBeaconRegion];
[self.locationManager startMonitoringForRegion:self.myBeaconRegion2];
[self.locationManager startMonitoringForRegion:self.myBeaconRegion3];
[self.locationManager startMonitoringForRegion:self.myBeaconRegion4];

NSSet *setOfRegions = [self.locationManager monitoredRegions];
    for (CLRegion *region in setOfRegions) {
        NSLog (@"region info: %@", region);
    }
InformationsquelleAutor user3196820 | 2014-01-15
Schreibe einen Kommentar