0

i'm developing an app. One of the firs thing i do (in AppDelegate) is to invoke OneSignal's initwithlaunchingoptions(...) This automatically makes my app displays "App wants to send notifications", asking for permissions. During my app lifecycle, i'll need other permissions from user (like calendar). I'd like to display (BEFORE all the permissions) a brief AlertView explaining what i'll ask and why. But how can i accomplish this if i can't move the OneSignal init from AppDelegate while my "explaining alert" happens only in viewDidLoad of the Main ViewController ?

Thanks.

Victor

1 Answers1

0

here is an example of UIViewController that has information about applications needs location data, when user presses UIButton, it asks for permission. you can do alike for all permissions.

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()
    }
}
JuicyFruit
  • 2,638
  • 2
  • 18
  • 35
  • Thanks JuicyFruit, but maybe i wasn't clear explaining my problem and my needs. The permission alert for notifications in Onesignal (the api) happens in appdelegate. I need to alert something BEFORE this happens. But how to display an alert before something begining in appdelegate's "application did finish launching with options" ? – Victor 'TheMac' Macavero Mar 19 '17 at 15:57