I've written an iOS app that scans for beacons.
I've set the app to monitor a pre-selected minor beacon, and have two methods, getBeaconMinor() and setBeaconMinor() that read/write a value from/to NSUserDefaults.
I use .syncronize() after each change. I can't replicate the problem, but some of my users are reporting that getBeaconMinor() is returning '0' the default value, days after they've successfully had setBeaconMinor() change the beaconMinor value to their beacon (in the range of 1-400). The default value '0' is used as a trigger for ALL beacons, whereas when a beaconMinor is set, the beacon UUID is limited to this minor value.
public static func getRegionMinor() -> CLBeaconMinorValue {
NSUserDefaults.standardUserDefaults().synchronize()
let beaconInfo = NSUserDefaults.standardUserDefaults()
let minorValue = beaconInfo.integerForKey("minorValue")
let value = CLBeaconMinorValue(minorValue)
return value
}
public static func setRegionMinor(minorValue: Int) {
NSLog("Setting beacon region for minor id \(minorValue)")
let beaconInfo = NSUserDefaults.standardUserDefaults()
beaconInfo.setInteger(minorValue, forKey: "minorValue")
NSUserDefaults.standardUserDefaults().synchronize()
//Restart beacon region monitoring
BeaconService.sharedService().tryMonitoringBeacons()
return
}