Skip to content
This repository has been archived by the owner on Feb 27, 2019. It is now read-only.

Added property applicationRootViewController #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions PermissionScope/PermissionScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
public var onDisabledOrDenied: cancelClosureType? = nil
/// View controller to be used when presenting alerts. Defaults to self. You'll want to set this if you are calling the `request*` methods directly.
public var viewControllerForAlerts : UIViewController?
/// View controller to be used when presenting alerts from from UIApplication -> window -> rootViewController
var applicationRootViewController: UIViewController? {
get {
return UIApplication.shared.windows.first?.rootViewController
}
}

/**
Checks whether all the configured permission are authorized or not.
Expand Down Expand Up @@ -1158,7 +1164,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
}))

DispatchQueue.main.async {
self.viewControllerForAlerts?.present(alert,
(self.viewControllerForAlerts ?? self.applicationRootViewController)?.present(alert,
animated: true, completion: nil)
}
}
Expand Down Expand Up @@ -1192,7 +1198,7 @@ typealias resultsForConfigClosure = ([PermissionResult]) -> Void
}))

DispatchQueue.main.async {
self.viewControllerForAlerts?.present(alert,
(self.viewControllerForAlerts ?? self.applicationRootViewController)?.present(alert,
animated: true, completion: nil)
}
}
Expand Down