【发布时间】:2023-03-05 05:16:01
【问题描述】:
我正在使用CLCircularRegion 开发应用程序。
我想在CLCircularRegion 中设置值。所以我做了region.setValue(forKey:key) 但它显示了
if CLLocationManager.locationServicesEnabled() {
for obj in pushInfoArr! {
let localLatiStr = obj["local_latit"] as! String
let localLongitStr = obj["local_longit"] as! String
let localMsg = obj["local_mesg"] as! String
let url = obj["cnnct_url"] as! String
let localLati = Double(localLatiStr)
let localLongi = Double(localLongitStr)
let center = CLLocationCoordinate2DMake(localLati!, localLongi!)
region = CLCircularRegion(center: center, radius: 1000, identifier: localMsg)
region.setValue(localMsg, forKey: "msg")
region.setValue(url, forKey: "url")
region.notifyOnEntry = true
self.locationManager.startMonitoring(for: region)
}
}
“由于未捕获的异常'NSUnknownKeyException'而终止应用程序, 原因: '[ setValue:forUndefinedKey:]:这个类不是键值 密钥 bb 的编码兼容”
我可以在CLCircularRegion中设置值(url)吗??
【问题讨论】:
-
请显示您正在使用的代码。你想设置什么值?边界框(“bb”)?您可以简单地通过
clRegion.radius = 123.4设置半径 - 类似的中心。见这里developer.apple.com/documentation/corelocation/clcircularregion -
更新问题!我想设置 url 和 message 来显示通知。当我通过通知运行应用程序时,我想转到保存的 url
-
据我所知,它所继承的
CLCircularRegion和CLRegion都没有属性msg和url- 所以你不能使用setValue来设置这些属性。
标签: swift swift4 clcircularregion