I have a strange error when attempting to advertise some service data.
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
if let beacon = beacons.first, username = NSUserDefaults.standardUserDefaults().objectForKey("username") {
var major = beacon.major.integerValue
var minor = beacon.minor.integerValue
let advertismentData:[String:AnyObject] = [
CBAdvertisementDataServiceUUIDsKey:[AppDelegate.MajorUUID, AppDelegate.MinorUUID, AppDelegate.IdentifierUUID],
CBAdvertisementDataServiceDataKey:[AppDelegate.MajorUUID: NSData(bytes: &major, length: sizeof(Int)), AppDelegate.MinorUUID: NSData(bytes: &minor, length: sizeof(Int)), AppDelegate.IdentifierUUID: username.dataUsingEncoding(NSUTF8StringEncoding)]
]
peripheralManger?.startAdvertising(advertismentData)
manager.stopRangingBeaconsInRegion(region)
}
}
When passed to start advertising the following error occurs:
2015-10-09 11:17:05.563 BeConvo[280:21134] -[CBUUID UTF8String]: unrecognized selector sent to instance 0x13dd5b420 2015-10-09 11:17:05.564 BeConvo[280:21134] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CBUUID UTF8String]: unrecognized selector sent to instance 0x13dd5b420' * First throw call stack: (0x185364f5c 0x199f5bf80 0x18536bc6c 0x185368c14 0x18526cdcc 0x184fe56b4 0x185361f00 0x184fe4634 0x184fe58a8 0x184fe56d8 0x185361f00 0x184fe4634 0x184fe44dc 0x184fe4704 0x184fe47e8 0x184fe6104 0x184fe7190 0x1000eb9a4 0x1000ebae0 0x185af5f04 0x185af0b14 0x185aeaef4 0x18531c48c 0x18531bdc4 0x18531a20c 0x185248dc0 0x19039c088 0x18a922f44 0x1000ec328 0x19a7868b8) libc++abi.dylib: terminating with uncaught exception of type NSException
If I remove the ServiceDataKey
or remove the contents of the dictionary then the advertisement succeeds.
func locationManager(manager: CLLocationManager, didRangeBeacons beacons: [CLBeacon], inRegion region: CLBeaconRegion) {
if let beacon = beacons.first, username = NSUserDefaults.standardUserDefaults().objectForKey("username") {
var major = beacon.major.integerValue
var minor = beacon.minor.integerValue
let advertismentData:[String:AnyObject] = [
CBAdvertisementDataServiceUUIDsKey:[AppDelegate.MajorUUID, AppDelegate.MinorUUID, AppDelegate.IdentifierUUID],
CBAdvertisementDataServiceDataKey:[]
]
peripheralManger?.startAdvertising(advertismentData)
manager.stopRangingBeaconsInRegion(region)
}
}
I have tried each one of the key/value pairs to see if it a specific one but any of them in any combination causes the error to occur.
Anyone got any ideas?
Thanks for your help.