问题描述
我正在开发一个 iBeacon
应用,我希望获得 Kontakt iBeacons
的所有属性。
I'm developing an iBeacon
app and I want to get all properties of Kontakt iBeacons
.
在stackoverflow中有2或3个主题,但没有人无法回答这个问题。
There are 2 or 3 topic about that in stackoverflow but nobody couldn't answer this.
我的应用是一个全局 iBeacon
项目。我可以看到 Estimote iBeacons
的所有属性也可以更改 major
, minor
值。我在 Estimote SDK
中使用connect方法做到了这一点但是我无法连接 Kontakt iBeacons
。我刚刚访问 major
, minor
和 rssi
值 Kontakt SDK
。
My app is a global iBeacon
project. I can see all properties of Estimote iBeacons
also can change major
,minor
values. I did this with using connect method in Estimote SDK
however I couldn't connect Kontakt iBeacons
. I just accessed major
,minor
and rssi
values with Kontakt SDK
.
我有一个 API密钥
来连接这些 iBeacons
但我无法连接。我只是想学习访问这些值的方法。有人可以告诉你这个吗?
I have an API key
to connect these iBeacons
but I couldn't connect. I just want to learn way of accessing these values. Can anybody tell the way of this ?
谢谢你,Halil。
推荐答案
client=[KTKClient new];
client.apiKey=@"apikey";
locationManager=[KTKLocationManager new];
locationManager.delegate=self;
NSError *error;
NSArray *array=[client getRegionsError:&error];
[locationManager setRegions:array];
//[locationManager stopMonitoringBeacons];
[locationManager startMonitoringBeacons];
beaconManager = [KTKBeaconManager new];
beaconManager.delegate = self;
[beaconManager startFindingDevices];
- (void)locationManager:(KTKLocationManager *)locationManager didRangeBeacons:(NSArray *)beacons{
for (CLBeacon *beacon in beacons) {
KTKBeacon *beaconData = [self _getDataForBeacon:beacon];
if (beaconData) beaconsData[beacon] = beaconData;
}
}
-(KTKBeacon *)_getDataForBeacon:(CLBeacon *)beacon
{
NSString *strURL = [NSString stringWithFormat:@"https://api.kontakt.io/beacon?proximity=%@&major=%@&minor=%@",
[beacon.proximityUUID UUIDString],beacon.major,beacon.minor];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:strURL]];
[request setValue:@"apikey" forHTTPHeaderField:@"Api-Key"];
[request setValue:@"application/vnd.com.kontakt+json; version=2" forHTTPHeaderField:@"Accept"];
NSError *error;
NSData *jsonData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSError * error1=nil;
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error1];
KTKBeacon *ktkBeacon = [[KTKBeacon alloc] initWithDictionary:dic];
NSLog(@"%@",dic);
return ktkBeacon;
}
这篇关于获取Kontakt iBeacon的房产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!