当前位置: 首页 > news >正文

南山做网站推广乐云seo自己造网站

南山做网站推广乐云seo,自己造网站,wordpress后端改写,星月教你做网站Overview 概述 [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pgnvehxf-1678717852996)(./blog_cover.png)] Core Location 提供的服务可以确定设备的地理位置、高度和方向,或者它相对于附近 iBeacon 设备的位置。 该框架使用设备上的所…

Overview 概述

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pgnvehxf-1678717852996)(./blog_cover.png)]

Core Location 提供的服务可以确定设备的地理位置、高度和方向,或者它相对于附近 iBeacon 设备的位置。 该框架使用设备上的所有可用组件收集数据,包括 Wi-Fi、GPS、蓝牙、磁力计、气压计和蜂窝硬件。

core class - CLLocationManager 核心类

Declaration 声明

class CLLocationManager : NSObject

Detailed Analysis 详解

是管理应用程序与位置相关的行为的核心类 (central place), 可以借助其 实例对象 来配置、启动和停止位置服务。进而实现如下:

  • Track (跟踪) large or small changes in the user’s current location with a configurable degree of accuracy (准确度/精度).
  • Report heading changes from the onboard compass. (译: 从机载罗盘报告航向变化。)
  • 监视感兴趣的地理区域并在有人进入或离开这些区域时生成事件。
  • Report the range to nearby Bluetooth beacons. (译: 向附近的蓝牙信标报告范围。)

在您的应用程序中创建一个或多个 CLLocationManager 对象,并在需要位置数据的地方使用它们。 创建 CLLocationManager 对象后,对其进行配置,以便 Core Location 知道报告位置更改的频率 (how often to report location changes)。 特别是,使用反映应用需求的值配置 distanceFilterdesiredAccuracy 属性。

Receiving data from location services 数据是怎样传递的 ?

A CLLocationManager object reports all location-related updates to its delegate object, which is an object that conforms to the CLLocationManagerDelegate protocol.

译(zh_CN): CLLocationManager 对象将所有与位置相关的更新报告给它的委托对象,这是一个符合 CLLocationManagerDelegate 协议的对象。

这里有两点需要注意:

⓪. 当 CLLocationManager 对象完成自己的初始化, 会调用代理的locationManagerDidChangeAuthorization(_:)方法上报App的定位权限状态, 所以在配置 CLLocationManager 时要马上指定delegate.

①. delegate方法回调与 CLLocationManager 实例化是同一线程.

官方原文如下

Assign the delegate immediately when you configure your location manager, because the system reports the app’s authorization status to the delegate’s locationManagerDidChangeAuthorization(_😃 method after the location manager finishes initializing itself. Core Location calls the methods of your delegate object using the RunLoop of the thread on which you initialized the CLLocationManager object. That thread must itself have an active RunLoop, like the one found in your app’s main thread.


Determining the availability of services 确定服务的可用性

// significant-change location service 上报明显的位置更新
class func significantLocationChangeMonitoringAvailable() -> Bool// 航向数据可能无法在所有基于 iOS 的设备上使用。在要求位置管理器传递航向相关事件之前,您应该检查此方法返回的值。
class func headingAvailable() -> Bool// 一个布尔值,指示小部件(widget)是否有资格接收位置更新。
var isAuthorizedForWidgetUpdates: Bool { get }//  the level of location accuracy the app has permission to use (App有权使用的定位精度级别)
var accuracyAuthorization: CLAccuracyAuthorization { get }// 能否监控指定的区域(regionClass: A region monitoring class from the MapKit framework. This class must descend from the CLRegion class.)
class func isMonitoringAvailable(for regionClass: AnyClass) -> Bool// 最常用, 系统定位服务是否开启, 如下图所求
class func locationServicesEnabled() -> Bool

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2QvDdIQA-1678717852996)(./locationServicesEnabled.jpeg)]


Requesting authorization for location services 权限请求

1. 请求 whenInUse 定位权限

func requestWhenInUseAuthorization() 

您必须调用此方法或 requestAlwaysAuthorization() 才能接收与位置相关的信息。 只要当前授权状态未确定 (CLAuthorizationStatus.notDetermined),您就可以调用 requestWhenInUseAuthorization()。

Important

Your app must be in the foreground to show a location authorization prompt.

此方法异步运行 (runs asynchronously) 并提示用户授予应用程序使用位置服务的权限。 用户提示包含来自应用程序 Info.plist 文件中 NSLocationWhenInUseUsageDescription 键 (key) 对应的文本,调用此方法时需要存在该键, 否则会CRASH。 用户提示 (prompt alert window) 显示以下选项,这些选项确定您的 App 可以获取的授权。

OptionAuthorization
Allow While Using AppWhen In Use authorization that does not expire.
Allow OnceTemporary When In Use authorization that expires when the app is no longer in use.
Don’t AllowDenied; no further authorization requests are allowed.

在用户做出选择并确定 (determines) 状态后,位置管理器 (the location manager, 即使 CLLocationManager 实例) 将结果传递给委托的 locationManager(_:didChangeAuthorization:) 方法。 如果方法调用前的初始授权状态不是 CLAuthorizationStatus.notDetermined,则此方法不执行任何操作,也不会调用 locationManager(_:didChangeAuthorization:) 方法。

如果用户的选择向您的应用授予 When In Use 授权,则您的应用可以启动任何位置服务,并且有资格在使用时接收结果。 如果用户选择授予临时使用时授权,则当应用程序不再使用时授权将过期,恢复为未确定状态 (CLAuthorizationStatus.notDetermined)。

有关应用程序何时被视为 whenInUse 的信息,请参阅 Choosing the Location Services Authorization to Request。

前台启动定位服务 Vs 后台启动定位服务
  • foreground starts: 当您的应用程序在前台启动标准位置服务时,如果您的应用程序在 Xcode 项目的功能选项卡中启用了后台位置更新,它们将继续在后台运行。当您的应用移动到具有活动位置服务的后台时 (moves to the background with active location services),系统会在状态栏中显示位置服务指示器 (indicator)。
  • background starts: 当您的应用程序在后台运行时尝试启动位置更新将失败。

Note

在 iOS 16 及更高版本中,主动跟踪用户位置或最近启用核心位置的应用程序会在控制中心显示一个指示器 (在最顶部🔝)。 通过仅在必要时和用户期望时监视设备的位置,注意电池使用和用户隐私。

2. 请求 Always 权限

func requestAlwaysAuthorization()
Discussion 讨论

要调用此方法,您必须在应用的 Info.plist 文件中同时拥有 NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription 键。 当前授权状态为以下任一状态时,您才可以调用:

  • Not Determined — CLAuthorizationStatus.notDetermined
  • When In Use — CLAuthorizationStatus.authorizedWhenInUse

当用户做出权限选择时,使用 CLLocationManager 委托上的 locationManager(_:didUpdateLocations:) 方法接收更新。

Core Location 限制对 requestAlwaysAuthorization() 的调用。 在您的应用程序调用此方法后,进一步的调用无效。

Request Always Authorization After Getting When In Use

要获得 Always 授权,您的应用必须首先请求 When In Use 权限,然后再请求 Always 授权。

如果用户在您的应用程序调用 requestWhenInUseAuthorization() 后授予 When In Use 权限,则调用 requestAlwaysAuthorization() 会立即提示用户请求 Always 权限。 如果用户使用 Allow Once 响应 requestWhenInUseAuthorization(),则 Core Location 会由于临时授权而忽略对 requestAlwaysAuthorization() 的进一步调用。

Core Location 提示用户使用来自 NSLocationAlwaysUsageDescription 的字符串授予权限。 用户提示显示以下选项,这些选项确定您的应用程序可以获得的授权:

OptionAuthorization
Keep Only While UsingCore Location leaves the authorization as When In Use. The delegate doesn’t receive any updates.
Change to Always AllowCore Location grants your app Always authorization. The delegate recieves CLAuthorizationStatus.authorizedAlways.
Request Always Authorization Directly

如果您的应用程序的当前状态为 CLAuthorizationStatus.notDetermined 并且您调用了 requestAlwaysAuthorization(),则 Core Location 在完全启用 Always 授权之前会使用两个提示。

第一个提示立即显示 NSLocationWhenInUseUsageDescription 中的字符串。 用户提示显示以下选项,这些选项确定您的应用程序收到的授权:

OptionAuthorization
Allow While Using AppCore Location grants your app a Provisional Always authorization. The delegate receives CLAuthorizationStatus.authorizedAlways.
Allow OnceCore Location grants your app a Temporary When in Use authorization. The delegate receives CLAuthorizationStatus.authorizedWhenInUse. This authorization expires when your app is no longer in use, reverting to CLAuthorizationStatus.notDetermined.
Don’t AllowCore Location marks your app with Denied authorization. The delegate receives CLAuthorizationStatus.denied.

当 Core Location 准备向需要 CLAuthorizationStatus.authorizedAlways 的应用程序传递事件时,会显示第二个提示。 如果应用程序处于 Provisional Always 状态,系统会显示第二个提示,其中包含来自 NSLocationAlwaysUsageDescription 的字符串。 当您的应用未运行时,Core Location 通常会显示第二个提示。

如果用户在临时始终状态下出现第二个提示时选择授予权限,您的应用程序将获得永久始终授权。 当用户响应时,您的应用会收到位置事件或使用修改后的授权调用您的委托。

当显示第二个提示时,用户会看到以下选项之一:

OptionAuthorization
Keep Only While UsingCore Location changes the authorization to When In Use. The delegate receives CLAuthorizationStatus.authorizedWhenInUse.
Change to Always AllowCore Location removes the provisional status, making the Always authorization permanent. The delegate doesn’t receive a callback.

如果用户在接近交付时间 (the time it was delivered) 响应提示并选择允许 Always 权限,则位置事件将发送到您的应用程序。

http://www.yayakq.cn/news/674087/

相关文章:

  • 淘宝客做网站教程设计风格好看的网站
  • 义乌建设公司网站市场调研报告1000字
  • 开发型网站报价方法越秀营销型网站
  • 学php网站开发好吗快乐麻花网站源码
  • 做网站链接怎么弄海沧区建设局网站市政处
  • 江门营销型网站建设网站静态
  • 求职网站网页模板下载品牌网站建设十a小蝌蚪
  • 网站如何做3d产品展示wordpress注册可见插件
  • 网站外包注意事项网页布局的常用方法
  • 做机械设备哪个网站好找人做彩票网站有哪些
  • 滨州做网站建设的公司福建住房和城乡建设厅网站首页
  • 杭州网站开发建设建设银行网址
  • 网上商城建设 网站定制开发网站建设需要什么教材
  • 网站开发有哪些职位国家重点建设裤网站
  • 深圳如何建立公司自己网站第一模板ppt免费下载
  • 漳州市城乡建设局网站wordpress音乐模版
  • 关于网站建设的小故事开网站做代发
  • 如何将自己做的网站发布到网上视频网站建设
  • 邳州微网站开发毕业设计网站开发题目
  • 哪里可学做网站网红营销模式有哪些
  • 泰州做网站的公司国家工信部网站域名查询系统
  • 怎样做中英文网站济宁北湖建设集团网站
  • 合肥电子商务网站建设厦门翔安建设局网站
  • aspnet东莞网站建设大淘客cms网站建设
  • 广州南站在哪个区广告优化师面试
  • 做网站要注意哪些方面wordpress关于
  • 怎么计算网站开发费用沐众科技网站建设
  • 河北建网站建筑公司名称大全
  • 浙江做网站找谁素材库大全高清素材免费下载
  • 烟台网站建设科技公司河北邯郸区号