我有一个 Estimote 信标,我正在使用我的 iOS 应用程序连接它。我能够成功地传递主要 id 和次要 id 等参数,但我还想获取电池电量和接近度,并在 URL 中传递这些参数。
我已经阅读了文档,似乎有一种方法可以做到这一点,但我无法弄清楚如何将它写入这个方法。任何想法都会非常有帮助!
-(void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region {
if([beacons count] > 0) {
if(!self.selectedBeacon) {
self.selectedBeacon = [beacons objectAtIndex:0];
}
else {
for (ESTBeacon* cBeacon in beacons) {
if([self.selectedBeacon.ibeacon.major unsignedShortValue] ==
[cBeacon.ibeacon.major unsignedShortValue] &&
[self.selectedBeacon.ibeacon.minor unsignedShortValue] ==
[cBeacon.ibeacon.minor unsignedShortValue])
{
self.selectedBeacon = cBeacon;
}
}
}
NSString *connectedToBeacon = [[NSUserDefaults standardUserDefaults]
stringForKey:@"connectedToBeacon"];
if ([connectedToBeacon isEqualToString:@"FALSE"]) {
NSString *userId = [[NSUserDefaults standardUserDefaults]
stringForKey:@"userId"];
NSString *beaconURL = [NSString stringWithFormat:@"%@/directory/page.php?
major=%i&minor=%i&user=%@", curr_host_variable,
[self.selectedBeacon.ibeacon.major unsignedShortValue],
[self.selectedBeacon.ibeacon.minor unsignedShortValue], userId];
NSData *BeaconURLResult = [NSData dataWithContentsOfURL:[NSURL
URLWithString:beaconURL]];
}
}
}