- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我很困惑......我今天有这个工作,现在我不知道发生了什么。它不是我的 iBeacon,因为我可以使用 Locate
iOS 应用找到它。我正在创建我自己的位置管理器,不确定您是否会准确地将其称为子类,因为我正在对 NSObject 进行子类化。在这里:
//
// LocationManager.swift
// onebeacon
//
// Created by Eamon White on 2/24/18.
// Copyright © 2018 EamonWhite. All rights reserved.
//
import Foundation
import CoreLocation
protocol LocationManagerDelegate: class {
func locationManagerDidUpdateLocation(_ locationManager: LocationManager, location: CLLocation)
func locationManagerDidUpdateHeading(_ locationManager: LocationManager, heading: CLHeading, accuracy: CLLocationDirection)
func locationManagerDidEnterRegion(_ locationManager: LocationManager, didEnterRegion region: CLRegion)
func locationManagerDidExitRegion(_ locationManager: LocationManager, didExitRegion region: CLRegion)
func locationManagerDidDetermineState(_ locationManager: LocationManager, didDetermineState state: CLRegionState, region: CLRegion)
func locationManagerDidRangeBeacons(_ locationManager: LocationManager, beacons: [CLBeacon], region: CLBeaconRegion)
}
class LocationManager: NSObject, CLLocationManagerDelegate {
private var locationManager: CLLocationManager!
weak var delegate: LocationManagerDelegate?
var beaconsToRange: [CLBeaconRegion]
var currentLocation: CLLocation!
override init() {
self.beaconsToRange = []
super.init()
self.locationManager = CLLocationManager()
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation
self.locationManager.distanceFilter = kCLDistanceFilterNone
self.locationManager.headingFilter = kCLHeadingFilterNone
self.locationManager.pausesLocationUpdatesAutomatically = false
self.locationManager.delegate = self
self.enableLocationServices()
}
func enableLocationServices() {
self.checkStatus(status: CLLocationManager.authorizationStatus())
}
func checkStatus(status: CLAuthorizationStatus) {
switch status {
case .notDetermined:
// Request when-in-use authorization initially
locationManager.requestAlwaysAuthorization()
break
case .restricted, .denied:
// Disable location features
print("send an alert that the app will not function")
break
case .authorizedWhenInUse:
locationManager.requestAlwaysAuthorization()
// Enable basic location features
break
case .authorizedAlways:
locationManager.startUpdatingLocation()
locationManager.startUpdatingHeading()
self.monitorBeacons()
// Enable any of your app's location features
break
}
}
func monitorBeacons() {
print("monitorBeacons()")
if CLLocationManager.isMonitoringAvailable(for:
CLBeaconRegion.self) {
print("monitorBeacons().monitoringIsAvailable")
// Match all beacons with the specified UUID
let proximityUUID = UUID(uuidString:
"12345678-B644-4520-8F0C-720EAF059935")
let beaconRegion = CLBeaconRegion(
proximityUUID: proximityUUID!,
major: 0x0001,
minor: 0x0002,
identifier: "iBeacon")
beaconRegion.notifyEntryStateOnDisplay = true;
self.locationManager?.startMonitoring(for: beaconRegion)
print("\(String(describing: self.locationManager?.monitoredRegions)) + monitoredRegions")
}
}
//MARK: - CLLocationManagerDelegate
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
for location in locations {
self.delegate?.locationManagerDidUpdateLocation(self, location: location)
}
self.currentLocation = manager.location
}
func locationManager(_ manager: CLLocationManager, didUpdateHeading newHeading: CLHeading) {
self.delegate?.locationManagerDidUpdateHeading(self, heading: newHeading, accuracy: newHeading.headingAccuracy)
}
func locationManager(_ manager: CLLocationManager, didEnterRegion region: CLRegion) {
if region is CLBeaconRegion {
// Start ranging only if the feature is available.
if CLLocationManager.isRangingAvailable() {
locationManager?.startRangingBeacons(in: region as! CLBeaconRegion)
// Store the beacon so that ranging can be stopped on demand.
beaconsToRange.append(region as! CLBeaconRegion)
}
}
self.delegate?.locationManagerDidEnterRegion(self, didEnterRegion: region)
}
func locationManager(_ manager: CLLocationManager, didExitRegion region: CLRegion) {
self.delegate?.locationManagerDidExitRegion(self, didExitRegion: region)
}
func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) {
if region is CLBeaconRegion {
print("determined state of beacon")
// Start ranging only if the feature is available.
if CLLocationManager.isRangingAvailable() {
print("determined state of beacon and started ranging")
locationManager?.startRangingBeacons(in: region as! CLBeaconRegion)
// Store the beacon so that ranging can be stopped on demand.
beaconsToRange.append(region as! CLBeaconRegion)
}
}
self.delegate?.locationManagerDidDetermineState(self, didDetermineState: state, region: region)
}
func locationManager(_ manager: CLLocationManager,
didRangeBeacons beacons: [CLBeacon],
in region: CLBeaconRegion) {
self.delegate?.locationManagerDidRangeBeacons(self, beacons: beacons, region: region)
}
func locationManagerShouldDisplayHeadingCalibration(_ manager: CLLocationManager) -> Bool {
return true
}
func locationManager(_ manager: CLLocationManager,
didChangeAuthorization status: CLAuthorizationStatus) {
self.checkStatus(status: status)
}
}
在我的 ViewController
中,我以一种非常直接的方式使用它,就像这样(在顶部:委托(delegate)方法......对于问题来说有点无关紧要,在底部:实例化):
import UIKit
import SceneKit
import ARKit
import CoreLocation
class ViewController: UIViewController, ARSCNViewDelegate, LocationManagerDelegate {
func locationManagerDidUpdateLocation(_ locationManager: LocationManager, location: CLLocation) {
}
func locationManagerDidUpdateHeading(_ locationManager: LocationManager, heading: CLHeading, accuracy: CLLocationDirection) {
}
func locationManagerDidEnterRegion(_ locationManager: LocationManager, didEnterRegion region: CLRegion) {
}
func locationManagerDidExitRegion(_ locationManager: LocationManager, didExitRegion region: CLRegion) {
}
func locationManagerDidDetermineState(_ locationManager: LocationManager, didDetermineState state: CLRegionState, region: CLRegion) {
}
func locationManagerDidRangeBeacons(_ locationManager: LocationManager, beacons: [CLBeacon], region: CLBeaconRegion) {
print("\(beacons) + beacons for ranging")
if beacons.count > 0 {
let nearestBeacon = beacons.first!
let major = CLBeaconMajorValue(truncating: nearestBeacon.major)
let minor = CLBeaconMinorValue(truncating: nearestBeacon.minor)
print("major: \(major)")
print("minor: \(minor)")
print("accuracy: \(nearestBeacon.accuracy)")
switch nearestBeacon.proximity {
case .immediate:
print("--- immediate ---")
case .near:
print("--- near ---")
case .far:
print("--- far ---")
case .unknown:
print("--- proximity unknown ---")
}
}
}
var sceneView: ARSCNView!
var locationManager: LocationManager!
override func viewDidLoad() {
super.viewDidLoad()
sceneView = ARSCNView()
locationManager = LocationManager()
locationManager.delegate = self
...
我的控制台输出是:
2018-02-24 20:40:30.927542-0500 onebeacon[1275:423523] [DYMTLInitPlatform] platform initialization successful
2018-02-24 20:40:32.799470-0500 onebeacon[1275:423484] Metal GPU Frame Capture Enabled
2018-02-24 20:40:32.801237-0500 onebeacon[1275:423484] Metal API Validation Enabled
monitorBeacons()
monitorBeacons().monitoringIsAvailable
Optional(Set([CLBeaconRegion (identifier:'iBeacon', uuid:12345678-B644-4520-8F0C-720EAF059935, major:1, minor:2)])) + monitoredRegions
所有 iBeacon 的详细信息都是正确的,它们不可能从今天早些时候发生变化,因为它一直被插入并且没有被访问。问题总结:它似乎将该区域添加到“要监视的区域”列表中,但监视似乎从未开始,因为我没有收到中继 iBeacon 信息的控制台消息。
更新
我会留下我提供的答案,因为它可能是其中的一部分(也许不是)......但现在它似乎开始了两次:
2018-02-24 21:35:13.341162-0500 onebeacon[1345:444027] [DYMTLInitPlatform] platform initialization successful
2018-02-24 21:35:16.504017-0500 onebeacon[1345:443977] Metal GPU Frame Capture Enabled
2018-02-24 21:35:16.505384-0500 onebeacon[1345:443977] Metal API Validation Enabled
monitorBeacons()
monitorBeacons().monitoringIsAvailable
Optional(Set([CLBeaconRegion (identifier:'iBeacon', uuid:12345678-B644-4520-8F0C-720EAF059935, major:1, minor:2)])) + monitoredRegions
2018-02-24 21:35:16.747004-0500 onebeacon[1345:443977] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2018-02-24 21:35:16.747969-0500 onebeacon[1345:443977] [MC] Reading from public effective user settings.
monitorBeacons()
monitorBeacons().monitoringIsAvailable
Optional(Set([CLBeaconRegion (identifier:'iBeacon', uuid:12345678-B644-4520-8F0C-720EAF059935, major:1, minor:2)])) + monitoredRegions
如您所见,monitorBeacons()...
行出现了两次,我检查以确保没有 LocationManager 的其他实例化,而且确实没有。
更新
我缩小了范围...问题似乎是 didDetermineState
函数最初没有触发,我必须走出信标的范围(或靠近它)...然后返回并触发 didDetermineState
方法,有人知道为什么当我从信标半径开始时它没有触发吗?
更新
看来我的手机正在识别它在一个区域中,因为当我走出该区域时,didExitRegion
方法会触发,然后是 didDetermineState
方法。 ..奇怪,因为如果 didExitRegion
方法正在触发,状态应该已经确定:
2018-02-24 23:01:09.650445-0500 onebeacon[422:33762] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-24 23:01:09.651978-0500 onebeacon[422:33762] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-24 23:01:15.007844-0500 onebeacon[422:33762] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-24 23:01:15.007893-0500 onebeacon[422:33762] [App] if we're in the real pre-commit handler we can't actually add any new fences due to CA restriction
2018-02-24 23:02:00.002451-0500 onebeacon[422:33762] Status bar could not find cached time string image. Rendering in-process.
...(put in for easier reading)...
did exit region --- CLBeaconRegion (identifier:'iBeacon', uuid:12345678-B644-4520-8F0C-720EAF059935, major:1, minor:2)
determined state of beacon
determined state of beacon and started ranging
[] + beacons for ranging
[] + beacons for ranging
[] + beacons for ranging
[] + beacons for ranging
[] + beacons for ranging
[] + beacons for ranging
[] + beacons for ranging
什么是预提交处理程序警告?这些是否相关?
最佳答案
我的 didDetermineState
函数在应用程序初始加载时停止工作。如果我走出信标范围,然后回到范围内 - didDetermineState
方法会触发(以及 enter/exit
区域方法)。我购买了另一个 iBeacon……它工作正常……另外,奇怪的是,当我同时使用两个信标时,两个信标在初始加载时都被 didDetermineState
检测到。我不确定为什么 didDetermineState
在单独使用时停止为一个信标工作。
关于ios - CLLocationManager 不监控区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48969476/
我已经在 ubuntu 14.0 上成功安装了 Zabbix 3.2 服务器主机上的 Z 是绿色的。不幸的是,JMX 是红色的。 Zabbix 服务器:192.168.1.112 带有 tomcat
我想制作一个仪表板,显示我们的 Azure 服务总线队列的状态,并显示“添加到队列的消息”、“队列长度”和“已处理的消息”等的历史记录。使用 Azure 管理门户,我可以看到,这些统计信息大部分是手动
我的 MYSQL 每天晚上都有事件,但我不太确定发生了什么,因为即使我将其设置得早于其他事件,它仍然在早上运行。 问题是,我如何检查运行事件的历史记录或日志,哪一个晚上锁了,哪一个是跑了没跑? 谢谢
1、监控log文件大小超过10g的server 和db 复制代码代码如下: create procedure db_sendmail_mssqllogsize as&n
本教程讨论如何使用 AspectJ 开源框架监控 Spring 应用程序在方法执行方面的性能。 传统上,监控每个 Java 方法所花费的时间的最简单方法是在方法的开头和结尾包含一些跟踪行: publi
有什么可以帮助 msmq 监控的吗?当消息出现在队列中并且在休假时相同时,我想获得一些事件/监视器。 最佳答案 查看 Windows 管理性能计数器。 如果您查看管理工具并找到“性能计数器”,您将能够
我的 Tomcat 中的一个巨大的 web 应用程序有时会开始使用过多的 DBCP 连接,从而导致问题。 为了进行调查,我想在每个时间点准确地知道什么线程/方法持有池的连接。不需要是实时的,事后分析就
在浏览器的整个页面生命周期中监视 cookie 并在 cookie 更改时触发事件的最佳 JS 或 JQuery 特定方法是什么? 最佳答案 据我所知,不可能将 change (或类似)事件直接绑定(
我想尽可能详细地报告我的笔记本的执行情况。简而言之,我想实时查看我的笔记本正在执行的每个操作。例如,我的一个函数有一个 sleep 周期为 5 秒的循环,我希望看到程序实际上正在 sleep 并且循环
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我一直在尝试使用 erlang:monitor/2 来监视 gen_server。不幸的是,每次我尝试这个时,Erlang shell 都会进入无限循环。 这是我为测试这一点而编写的测试程序。 -mo
Azure 容器服务是否与 Azure Monitor 集成?想知道对 kubernetes 集群进行日志记录/监控的最佳方法是什么? 最佳答案 如果您正在 Azure 上寻找监视工具,您可能需要使用
我想使用 编写一个 shell 脚本来监控集群中的消费者滞后 bin/kafka-run-class.sh kafka.tools.ConsumerOffsetChecker --zkconnect
在 .NET 中,假设 thread A 锁定了一个对象。同时,线程B和线程C被阻塞,等待线程A解锁对象。 现在,线程 A 解锁了对象。接下来将选择哪个线程(B 或 C)?它是如何确定的? 最佳答案
我搜索过这个主题,但发现很少有有用的细节。有了这些细节,我尝试编写一些代码如下。 注意:在将此帖子标记为重复之前,请将此帖子中共享的详细信息与其他帖子进行比较,而不仅仅是按主题。 - (NSArray
目录 1、指标监控 2、常用的监控端点 3、定制EndPoint 4、spring boot admin(可以使用)
我们使用 Prometheus 和 Grafana 来监控我们的 Kafka 集群。 在我们的应用程序中,我们使用 Kafka 流,Kafka 流有可能因异常而停止。我们正在记录事件 setUnCau
我正在建立一个复杂的网络仿真,并试图捕捉一些重要的性能测量。 我在服务器上运行了 mininet,并且我将视频从一个 mininet 主机流式传输到另一个(使用 -nodisp 选项,因为我没有 GU
Jenkins 的 openstack-plugin 使用 openstack4j 与 openstack 云对话。我正在寻找一种方法,我们可以从客户端的角度监控 openstack4j 所做的 ht
我正在处理一项需要监控 Thunderbolt 端口连接变化的要求。 (当连接或断开 Thunderbolt 电缆时)。 我尝试使用 IOServiceMatching(kIOUSBInterface
我是一名优秀的程序员,十分优秀!