什么发送beaconsData到getActionsForBeacons(Kontakt beacons)

时间:2014-08-01 13:55:17

标签: ios objective-c ibeacon unrecognized-selector estimote

我正在使用Kontakt信标和iOS SDK,我的代码一次又一次地在部分崩溃以获取我的信标的动作

Kontakt SDK文档为here

- (void)locationManager:(KTKLocationManager *)locationManager
        didRangeBeacons:(NSArray *)beacons {

    NSMutableDictionary *beaconsData = [NSMutableDictionary new];
    for (CLBeacon *beacon in beacons) {
        KTKBeacon *beaconData = [self _getDataForBeacon:beacon];
        if (beaconData) [beaconsData setObject:beaconData forKey:beacon];
    }
    self.actionManager = [KTKActionManager new];
    self.actionManager.delegate = self;
    [self.actionManager processBeacons:beacons withData:beaconsData];
}

获取信标数据的方法

-(NSDictionary *)_getDataForBeacon:beacon
{
    NSLog(@"%@",beacon);
    NSData * jsonData = [NSData dataWithContentsOfURL:[NSURL
                                                       URLWithString:@"****"]];
    NSError * error=nil;
    NSDictionary *dic = [NSJSONSerialization
                         JSONObjectWithData:jsonData options:kNilOptions error:&error];
    NSLog(@"%@",dic);

    NSArray *array = [NSArray arrayWithObject:beacon];
    NSDictionary *data = [self.client getActionsForBeacons:array changedSince:0 error:&error]; //##It crashes here##
    NSLog(@"%@",data);

    return data;
}

dic 字典

的内容
{
  "id" : "42152577-e3d2-4687-b499-8112402b2ca2",
  "major" : 56809,
  "txPower" : 3,
  "browserActions" : [

  ],
  "serial" : "",
  "uniqueId" : "OFSP",
  "interval" : 350,
  "urlRequestActions" : [

  ],
  "minor" : 57237,
  "masterPassword" : null,
  "password" : null,
  "alias" : null,
  "venue" : {
    "id" : "f7fe1874-c9c2-4f88-980b-876681e2eb18",
    "description" : "Flat room",
    "rates" : [

    ],
    "users" : [

    ],
    "managers" : [

    ],
    "priv" : true,
    "beacons" : [

    ],
    "lat" : null,
    "beaconsCount" : 1,
    "lng" : null,
    "coverType" : null,
    "name" : "Home"
  },
  "contentActions" : [
    {
      "actionType" : "CONTENT",
      "beacon" : null,
      "distance" : null,
      "id" : "b0897c61-55c3-49c9-9f23-538f279ca1ce",
      "owner" : {
        "venues" : [

        ],
        "password" : null,
        "active" : false,
        "id" : "307d0ef9-7207-47ec-980f-9382cff9b773",
        "company" : {
          "id" : "c95cc0fc-70fb-4a82-960c-c91845654fc8",
          "name" : "Shubhank Gaur",
          "key" : null
        },
        "email" : "shubhank008pp@gmail.com",
        "salt" : null
      },
      "contentType" : "image\/jpeg",
      "contentLength" : 354008,
      "impairmentTypes" : [

      ],
      "proximity" : "IMMEDIATE",
      "contentCategory" : "IMAGE"
    }
  ],
  "proximity" : "f7826da6-4fa2-4e98-8024-bc5b71e0893e",
  "name" : "Kontakt",
  "actionsCount" : 1
}

最后这是错误

  

2014-07-24 17:52:10.249 Code64Beacons [371:60b] - [CLBeacon标识符]:   无法识别的选择器发送到实例0x15593ef0   2014-07-24 17:52:10.250 Code64Beacons [371:60b] *终止app到期   未被捕获的异常'NSInvalidArgumentException',原因:' - [CLBeacon   标识符]:无法识别的选择器发送到实例0x15593ef0'   * 第一次抛出调用堆栈:   (0x30d00f0b 0x3b497ce7 0x30d04837 0x30d03137 0x30c52098 0xaa41b 0xa60b9   0xa5bd7 0xa85bf 0x311c5e91 0x311c0aeb 0x311ba081 0x30ccc01d 0x30ccb397   0x30cca001 0x30c34769 0x30c3454b 0x35ba16d3 0x33593891 0xa52cd 0x3b995ab7)   libc ++ abi.dylib:以NSException类型的未捕获异常终止   (LLDB)`

1 个答案:

答案 0 :(得分:0)

你可能已经解决了这个问题,因为为时已晚。但下面是获取信标数据所需的完整代码,对于遇到此问题的其他人可能会有用。

-(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:@"YOUR_API_KEY" forHTTPHeaderField:@"Api-Key"];
    [request setValue:@"application/vnd.com.kontakt+json; version=2" forHTTPHeaderField:@"Accept"];
    NSData *jsonData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSError * error=nil;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
    NSLog(@"%@",dic);
    KTKBeacon *newBeacon = [[KTKBeacon alloc] initWithDictionary:dic];
    return newBeacon;
}
相关问题