我正在开发一个需要位置访问权限的应用程序。我创建了一个 View Controller ,询问用户是否允许使用 2 个按钮。但是当我点击允许按钮时,设备会生成它自己的弹出窗口,要求用户访问位置。我可以避免弹出窗口并仅将允许弹出窗口的功能添加到我的应用程序本身的允许按钮的代码中吗?
最佳答案
不,您无法避免系统弹出窗口。按照苹果
Always request authorization at the point where you actually plan to use location services to perform a task. Requesting authorization may display an alert to the user. If it is not clear to the user that your app is using location services for a useful purpose, the user may deny your request to use those services.
此外,在确定应用的授权状态之前启动位置服务是安全的。虽然您可以启动定位服务,但这些服务不会传送任何数据,直到授权状态更改为 authorizedAlways
或 authorizedWhenInUse
。要在授权状态更改时收到通知,请在您的位置管理器委托(delegate)中实现 locationManager(_:didChangeAuthorization:)
方法。
关于ios - 我可以在不在 iphone 中生成默认弹出窗口的情况下获取位置访问权限吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39608230/