我正在开发iBeacon应用程序,并且想要获得Kontakt iBeacons的所有属性。

关于stackoverflow有2或3个主题,但是没人能回答。

我的应用程序是一个全球iBeacon项目。我可以看到Estimote iBeacons的所有属性,也可以更改majorminor的值。我使用Estimote SDK中的connect方法来完成此操作,但是我无法连接Kontakt iBeacons。我刚刚使用major访问了minorrssiKontakt SDK值。

我有一个API key来连接这些iBeacons,但是我无法连接。我只想学习访问这些值的方法。有人可以告诉我这种方式吗?

谢谢,哈利尔。

最佳答案

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;
}

关于ios - 获取Kontakt iBeacon的属性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29694029/

10-10 09:47