ios中位置权限

In iOS 13, Apple made a big changes in location permission’s behaviour, especially for “Always Allow” permission. As I have been working full time on a location tracking app since 3 years, I encountered a big challenge and learned a lot from it when supporting iOS 13. In this story, I would like to share my experience when dealing with “Always Allow” request, and how iOS 13.4 brought a big improvement for user experience (though it looks like a workaround) to this request.

在iOS 13中,Apple对位置权限的行为进行了重大更改,尤其是对于“始终允许”权限。 自3年以来我一直在全职工作于位置跟踪应用程序时,在支持iOS 13时遇到了巨大挑战并从中学到了很多。在这个故事中,我想分享我在处理“始终允许”方面的经验。请求,以及iOS 13.4如何为该请求带来了极大的用户体验改善(尽管这似乎是一种解决方法)。

Note: I assume that audience knows implementing CoreLocation’s permission and functionality. In this story, I discuss only behaviour aspect, this is not a coding tutorial.

注意 :我假设读者知道实现CoreLocation的权限和功能。 在这个故事中,我仅讨论行为方面,这不是编码教程。

权限行为摘要 (Summary of permission’s behaviour)

In the code, developers can request two types of permission: “When in use” (requestWhenInUseAuthorization) and “Always Allow” (requestAlwaysAuthorization). In iOS 13, whichever option we use, we get this system popup:

在代码中,开发人员可以请求两种类型的权限:“使用中”( requestWhenInUseAuthorization )和“始终允许”( requestAlwaysAuthorization )。 在iOS 13中,无论使用哪种选项,我们都会显示以下系统弹出窗口:

This popup uses NSLocationWhenInUseUsageDescription string in the message. As you can see, even you request for “Always Allow”, this option is not available to choose anymore.

该弹出NSLocationWhenInUseUsageDescription在消息中使用NSLocationWhenInUseUsageDescription字符串。 如您所见,即使您请求“始终允许”,此选项也不再可供选择。

If user selects “Don’t Allow”, in the app and in the iOS Setting, we get .denied permission. This is a straightforward case to handle.

如果用户在应用程序和iOS设置中选择“不允许”,我们将获得.denied权限。 这是一个简单的案例。

If user selects “Allow Once”, in the app we received .authorizedWhenInUse permission, and “Ask next time” in the iOS Setting. This option is new in iOS 13, and it replace the “Always Allow” option. If user selects this option, when restarting the app, both in app’s and iOS Setting’s permission status change back to .notDeterminated so we can request again the location permission.

如果用户选择“允许一次”,则在应用程序中,我们将获得.authorizedWhenInUse权限,并在iOS设置中获得“下次询问”。 此选项是iOS 13中的新增功能,它取代了“始终允许”选项。 如果用户选择此选项,则在重新启动应用程序时,应用程序和iOS设置中的权限状态都将更改回.notDeterminated 因此我们可以再次请求位置权限。

If user selects “Allow While Using App”, well, this is the confusing part since the behaviour is different between requesting “When in Use” and “Always Allow”, and between iOS versions.

如果用户选择“在使用应用程序时允许”,那么这是令人困惑的部分,因为在请求“使用时”和“始终允许”之间以及iOS版本之间的行为是不同的。

In case app requests “When in Use”, this choice “Allow While Using App” gives both app and system setting the .authorizedWhenInUse permission. It’s good since app get what it’s supposed to get.

如果应用程序请求“使用中”,则此选项“允许使用应用程序”将同时为应用程序和系统设置.authorizedWhenInUse权限。 很好,因为应用程序可以达到预期的效果。

In case app requests “Always Allow”, this choice “Allow While Using App” gives app .authorizedAlways and system setting .authorizedWhenInUse.

如果应用程序请求“始终允许”,则此选项“在使用应用程序时允许”将为应用程序.authorizedAlways 和系统设置.authorizedWhenInUse

authorizedWhenInUse in app ; authorizedWhenInUse in setting (source: WWDC 2019)
在应用中已授权WhenInUse; 设置中使用 whenWhenUse (来源: WWDC 2019 )

You may ask “Why are they different? Is it a bug?”. Well, you’re not alone. This is what Apple called deferred permission, or provisional permission. Whatever we call it, it means the real “Always Allow” permission will be shown later, at the time decided by iOS system.

您可能会问:“为什么它们不同? 这是一个错误吗?”。 好吧,你并不孤单。 这就是苹果所谓的延期许可或临时许可。 无论我们叫什么,这意味着真正的“始终允许”权限将在iOS系统决定的时间稍后显示。

WWDC 2019)WWDC 2019 )

In real life, user can expect to see the popup below a few days later:

在现实生活中,用户可以期待几天后看到以下弹出窗口:

Actually, this is the real popup for “Always Allow”, which uses your NSLocationAlwaysAndWhenInUseUsageDescription string as message. If user selects “Change to Only While Using”, both app and setting get the permission .authorizedWhenInUse. Otherwise, if user selects “Always Allow”, then both app and setting now get the “true” .authorizedAlways.

实际上,这是“始终允许”的真正弹出窗口,它使用您的NSLocationAlwaysAndWhenInUseUsageDescription字符串作为消息。 如果用户选择“仅在使用时更改”,则应用程序和设置都将获得权限.authorizedWhenInUse 。 否则,如果用户选择“总是允许”,那么这两个程序,现在设置得到了“真正的” .authorizedAlway s

This new behaviour in iOS 13 imply frustration for tracking app’s designers. Since app get the “pretended” Always Allow permission at the beginning, user may accidentally “Change to Only While Using” on second confirmation, and disrupt app’s functionality. Many companies had to design a force setting permission screen in their apps to redirect user to location permission in iOS Setting and let users manually choose the correct one.

iOS 13中的这一新行为暗示了跟踪应用程序设计师的挫败感。 由于应用程序在开始时就获得了“伪装”的“始终允许”权限,因此用户可能会在第二次确认时不小心将“更改为仅在使用时”,从而破坏了应用程序的功能。 许多公司必须在其应用程序中设计一个强制设置权限屏幕,以将用户重定向到iOS设置中的位置权限,并让用户手动选择正确的权限。

iOS 13.4的改进 (Improvement for iOS 13.4)

Since iOS 13.4, it seems like Apple realized that it need some user experience improvement. So, as I mentioned at the beginning, they decided to allow developer to show the second popup immediately. But it doesn’t come with a straightforward implementation. As stated in requestAlwaysAuthorization documentation in Xcode 11.4:

从iOS 13.4开始,Apple似乎意识到需要改善一些用户体验。 因此,正如我在开始时提到的那样,他们决定允许开发人员立即显示第二个弹出窗口。 但是它并没有一个简单的实现。 如Xcode 11.4中的requestAlwaysAuthorization文档中所述:

An application which currently has “when-in-use” authorization and has never before requested “always” authorization may use this method to request “always” authorization one time only

当前具有“使用中”授权且从未请求过“永远”授权的应用程序可以使用此方法仅一次请求“永远”授权

In fact, this means, for a fresh user (never gives any location permission before in app), we must show firstly a “When in Use” request. If user gives “When in Use” permission, then we make the “Always Allow” request to pop the second one. You can inspire from the code below:

实际上,这意味着,对于新用户(在应用内之前绝不授予任何位置许可),我们必须首先显示“使用时”请求。 如果用户授予“使用中”权限,则我们发出“始终允许”请求以弹出第二个请求。 您可以从以下代码中获得启发:

Simple, right? In iOS 13.4, we can just setup a closure, so when user answer the first popup, we can detect if they give the “right” choice and if so, show the “Always Allow” request.

简单吧? 在iOS 13.4中,我们可以设置一个闭包,因此当用户回答第一个弹出窗口时,我们可以检测到他们是否给出了“正确”选择,如果是,则显示“始终允许”请求。

Using this code, we will get the desired result:

使用此代码,我们将获得所需的结果:

Happy path’s sequence when running this code on iOS 13.4.
在iOS 13.4上运行此代码时,幸福路径的顺序。

然后去哪儿? (Where to go from here?)

If you want to understand deeper in Core Location changes in iOS 13, I suggest the excellent presentation from WWDC 2019: What’s New in Core Location

如果您想更深入地了解iOS 13中的核心位置更改,我建议WWDC 2019的精彩演讲: 核心位置的新功能

翻译自: https://medium.com/swlh/location-permission-in-ios-13-f9e10917c05e

ios中位置权限


http://www.taodudu.cc/news/show-5029357.html

相关文章:

  • 利用VMware搭建虚拟开发环境及VMware虚拟机上网
  • 58、【网络工程师精华篇】50种网络故障及解决方法大集合
  • 代理服务器软件CCPROXY
  • ADSL组建局域网快捷方案 (转)
  • vmware虚拟机中的linux操作系统能够上网
  • 代理服务器基础知识
  • (9) SyGate 4.0实现局域网共享上网3
  • 发现了个比HomeShare更好用的单网卡共享上网的东西Sygate
  • Sygate3.0 的用法
  • 关于syGate代理端口冲突问题
  • 配置sygate客户端
  • (8) SyGate 4.0实现局域网共享上网2
  • Sygate Personal Firewall 5.6
  • (7) SyGate 4.0实现局域网共享上网1
  • 怀念曾经的sygate firewall
  • CCProxy的功能大部分与Sygate、Wingate相同,是一个优秀的反向代理服务器软件
  • 用Sygate实现单网卡共享上网
  • 使用SyGate代理服务器使局域网连接到Internet
  • sygate45chs激活
  • 单位共享上网sygate代理服务软件完全解决方案
  • Sygate
  • Spring 之MultipartFile转换File 并鉴别File Mine Type 类型
  • Android音频开发(1):音频相关知识
  • 3gpp 中的AAC和AMR
  • python 将MP3格式转换为WAV格式(ffmpeg安装,使用pycharm安装包)
  • java 3gpp转mp3_ffmpeg的mp3lame功能打开了,可以把音频流也转换出来了
  • css calc()函数 动态根据屏幕宽度计算宽度
  • android查看屏幕大小,android获取屏幕尺寸的三种代码
  • 分辨率,屏幕尺寸,屏幕密度,dp,px,sp
  • android 屏幕dp值计算

ios中位置权限_iOS 13中的位置权限相关推荐

  1. IOS13图标尺寸_iOS 13 中 30+ 个精心设计的出色功能。

    Apple 于北京时间 9月20日今日凌晨正式推送 iOS 13 正式版,iOS 13 对整个系统做出了多项改进,比如应用启动速度的明显提升,还有「深色模式」深得 OLED 设备用户的喜爱,升级后的 ...

  2. ios 地图 省市轮廓_iOS 14中的新增功能:视觉轮廓检测

    ios 地图 省市轮廓 WWDC20 (WWDC20) Apple's WWDC 2020 (digital-only) event kickstarted with a bang. There we ...

  3. ios支付 选择货币_iOS开发中金钱货币的计算问题

    ios开发中涉及到和货币价格计算相关的,都需要注意计算精度的问题. 服务器有可能返回的金钱是int float double string NSNumber, 单纯的float.double的计算都会 ...

  4. ios label 高度紫石英_IOS开发中UILabel自适应大小显示的方法

    1,根据label中的文字内容自动换行显示的方法 1>,认识两个属性 @property(nonatomic) NSIntegernumberOfLines; @property(nonatom ...

  5. 在linux中的sort命令,linux中sort命令

    功能说明:将文本文件内容加以排序,sort可针对文本文件的内容,以行为单位来排序. 参 数: -b 忽略每行前面开始出的空格字符. -c 检查文件是否已经按照顺序排序. -d 排序时,处理英文字母.数 ...

  6. iOS模拟器中图片在mac电脑中的实际位置

    iOS模拟器中图片在mac电脑中的实际位置 位置:/Users/hyf/Library/Developer/CoreSimulator/Devices/CE85A44B-79C7-497D-A020- ...

  7. 苹果nfc功能怎么开启_iOS 13系统中NFC标签已现身,苹果iPhone如何开启NFC功能?

    搞机哥最近收到很多小土豪们的私信: "搞机哥,我苹果升级了iOS 13,能告诉我怎么用吗?" 当然可以,哥愿意尽哥所能,倾哥所有,不遗余力地告诉你. 苹果如何开启NFC功能,相信还 ...

  8. ios label 高度紫石英_iOS中iconfont(图标字体)的基本使用

    前言 近日在做项目时,项目组有提出iconfont的技术,便开始查询相关资料.iconfont技术的主要目的是为减少应用体积而生.首先icon代表图标 font代表字体.此技术便是将图标转化为字体,从 ...

  9. linux用户名和密码6,Linux系统中(CentOS 7)的用户和权限管理

    用户和组 用户信息文件 /etc/passwd (1 2 3 4 5 6 7) root:x:0:0:root:/root:/bin/bash 用户信息,以 : 分割字段 daemon:x:2:2:d ...

最新文章

  1. 大型网站技术架构:核心原理与案例分析 mobi_阿里面试官:你会高并发技术吗?...
  2. Java并发基础02. 传统线程技术中的定时器技术
  3. 关于小程序·云开发峰会,你想get的干货全在这了!
  4. java 线程池 -- (Java并发)
  5. 简洁明了!Java实现单向环形链表以解决约瑟夫环Josepfu问题
  6. ArcGIS 城市生活区用地适宜性评价(一)
  7. js 阻止冒泡 在控件的 onxxx 事件中调用就可以阻止父控件也响应消息了
  8. pycharm设置工程运行环境
  9. Filter过滤器详解
  10. 星期、月份英文缩写对照表
  11. 金融领域的数字化转型和科技创新有哪些应用?
  12. 论坛议程|COSCon'22 大数据(D)
  13. 开始尝试淘宝直通车推广
  14. 十大运动蓝牙耳机品牌排行榜,六款值得买的运动耳机推荐
  15. html网页设计小作业(个人主页)
  16. ansible一键部署zabbix并配置自动发现
  17. 开关调色新世界BP2888电源解决方案
  18. 2018款Y7000升级硬盘+迁移、升级黑苹果
  19. HBuildX的下载安装教程
  20. 如何查询Office版本号

热门文章

  1. vue中elementUi筛选后分页页码恢复到第一页
  2. 产品经理,如何制定完美的产品策略?
  3. 用flex布局画骰子的六个面
  4. 小壁虎EFM32之ADC 采集电压
  5. 计算机岗位需要具备什么技能点
  6. 【计算机图形学】基于GPU预计算的大气层光效渲染
  7. 气传导蓝牙耳机品牌推荐,精选几款性价比超高的气传导耳机
  8. ArrayList详解,看这篇就够了
  9. The New C++ -- 基本数据类型和字面值常量 (5. 宽字符类型和宽字符字面值常量)
  10. 聊一聊团队管理:如何搭建自己的管理体系!