ios - CLLocationManager startMonitoringForRegion 在 ios 8.4 上崩溃

标签 ios swift core-location ibeacon estimote

我发现 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/

相关文章:

swift - 更改键盘扩展中的 View 高度 (iPhone X)

ios - shouldAutoRotate 不能快速工作

ios - 如果我打开了位置服务,那么当我的应用程序进入后台模式时,它怎么会被杀死?

swift - 如何在速度测量过程中消除不可预测的速度峰值?

ios - 如何在 swift 中全局使用解析值

ios - 解决导航栏和覆盖

iphone - 自定义 TabBar 颜色 iOS 5.0.1

swift - 点击 UITextView swift 调用 segue?

ios - 是什么导致错误 "cannot convert value of type ' CLLocation.Type' 到预期参数类型 'CLLocation'“

ios - Mac OS 和 iOS 支持集成 Windows 身份验证和 IIS