ios,在其他所有内容之前显示提醒,告知用户我们需要“一些”权限

时间:2017-03-19 09:09:30

标签: ios swift xcode appdelegate onesignal

我正在开发一款应用。我做的第一件事(在AppDelegate中)是调用OneSignal的initwithlaunchingoptions(...) 这会自动使我的应用程序显示“App想要发送通知”,要求获得权限。 在我的应用生命周期中,我需要用户的其他权限(如日历)。 我想显示(在所有权限之前)一个简短的AlertView,解释我会问什么以及为什么。 但是,如果我的“解释警报”只发生在主ViewController的viewDidLoad中,我怎么能从AppDelegate移动OneSignal init呢?

感谢。

维克多

1 个答案:

答案 0 :(得分:0)

这是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()
    }
}