0

I am using Kontakt beacons and iOS SDK and my code is again and again crashing at the part to get Actions for my beacons

Kontakt SDK docs are 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];
}

The method to get beacon Data

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

The contents of dic dictionary

{
  "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
}

And finally here is the error

2014-07-24 17:52:10.249 Code64Beacons[371:60b] -[CLBeacon identifier]: unrecognized selector sent to instance 0x15593ef0 2014-07-24 17:52:10.250 Code64Beacons[371:60b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CLBeacon identifier]: unrecognized selector sent to instance 0x15593ef0' * First throw call stack: (0x30d00f0b 0x3b497ce7 0x30d04837 0x30d03137 0x30c52098 0xaa41b 0xa60b9 0xa5bd7 0xa85bf 0x311c5e91 0x311c0aeb 0x311ba081 0x30ccc01d 0x30ccb397 0x30cca001 0x30c34769 0x30c3454b 0x35ba16d3 0x33593891 0xa52cd 0x3b995ab7) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)`

modusCell
  • 13,151
  • 9
  • 53
  • 80
vongolashu
  • 375
  • 3
  • 17

1 Answers1

0

You might have resolved this as its too late. But below is the full code which you need to get the beacon data, might be useful for others running into this.

-(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;
}
Devang
  • 320
  • 3
  • 12