gpt4 book ai didi

ios,在其他所有内容之前显示警报,通知用户我们需要 "some"权限

转载 作者:行者123 更新时间:2023-11-30 12:35:45 25 4
gpt4 key购买 nike

我正在开发一个应用程序。我(在 AppDelegate 中)做的第一件事是调用 OneSignal 的 initwithlaunchingoptions(...)这会自动使我的应用程序显示“应用程序想要发送通知”,请求权限。在我的应用程序生命周期中,我需要用户的其他权限(例如日历)。我想(在所有权限之前)显示一个简短的 AlertView,解释我要问的问题以及原因。但是,如果我无法从 AppDelegate 中移动 OneSignal init,而我的“解释警报”仅发生在主 ViewController 的 viewDidLoad 中,我该如何实现此目的?

谢谢。

维克多

最佳答案

这是一个 UIViewController 的示例,其中包含有关应用程序需要位置数据的信息,当用户按下 UIButton 时,它会请求许可。您可以对所有权限执行相同的操作。

class LocationRequestViewController: UIViewController, CLLocationManagerDelegate {

var locationManager = CLLocationManager()

override func viewDidLoad() {
super.viewDidLoad()
self.locationManager.delegate = self
}

//when user authorised or denied ->push next `UIViewController`
func locationManager(_: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse || status == .denied {
let destinationVC = self.storyboard!.instantiateViewController(withIdentifier: "Notifications Request")
self.navigationController?.pushViewController(destinationVC, animated: true)
}
}

@IBAction func requestLocation(_: UIButton) {
self.locationManager.requestWhenInUseAuthorization()
}
}

关于ios,在其他所有内容之前显示警报,通知用户我们需要 "some"权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42884793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com