我发现 startMonitoringForRegion
仅在 iOS 8.4 上崩溃并给我这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: major)'
*** First throw call stack:
(0x2af4a49f 0x38744c8b 0x2ae67c63 0x3c3bbd 0x380d6b 0x17fcd8 0x19f170 0xebe9db 0xebe9c7 0xec23ed 0x2af103b1 0x2af0eab1 0x2ae5c3c1 0x2ae5c1d3 0x3225a0a9 0x2e46a7b1 0x2ad734 0x38cc4aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
认为 CLBeaconRegion
主要值可以为零。所以我不知道发生了什么。
代码如下:
if let context = (UIApplication.sharedApplication().delegate as? AppDelegate)?.managedObjectContext{
var dataFetch = DataFetcher()
dataFetch.fetchBeacons(context, completion: { (success) -> Void in
dispatch_async(dispatch_get_main_queue()) {
var beacons = Beacon.getAllBeacons(context)
if let uuid = beacons.first?.uuid {
var region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: uuid), identifier: "iBeacon")
region.notifyOnEntry = true
region.notifyOnExit = true
if self.isBluetoothOn {
self.manager.startMonitoringForRegion(region)
}
}
}
})
}
最佳答案
错误是
setObjectForKey: object cannot be nil (key: major)
这更有可能是 NSDictionary 错误。正如它所说,您将一个对象设置为 nil。在你的 major
中检查一次 key object 是 nil 或在你的 viewcontroller
关于ios - CLLocationManager startMonitoringForRegion 在 ios 8.4 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35404773/