我已經完成了兩篇教程,並且正在閱讀基本的C語言。在過去一週左右的時間裏,通過學習最好的學習並編寫了幾個輕型應用程序。我正在儘快編寫一些將使用ibeacon的應用程序。當我瀏覽一些樣本並閱讀參考指南時,我發現可以通過爲每個UUID運行startMonitoringForRegion來掃描多個區域。好的,所以我想我可以爲每個UUID運行它,但這不起作用。我確定我正在做一些基本完全錯誤的事情......下面的代碼是一個徹頭徹尾的破解 - 一旦我獲得了語義,我將通過API調用從數據庫中提取UUID並通過它們循環來激活監控。下面的代碼在上一個循環中僅顯示四個UUID中的兩個。如何在Objective-C中使用startMonitoringForRegion掃描多個區域
在標題:
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion2;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion3;
@property (strong, nonatomic) CLBeaconRegion *myBeaconRegion4;
主:
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);
}
這是正確的。 – davidgyoung
太棒了,作品!非常感謝! – user3196820
我不能在OS 7.1.1上使用我的iphone5s。但它曾用於一個燈塔區域。任何人都可以通過這種方式工作? – Forrest