Supports bypassing “Undeclared Permissions” error while sources are in beta

Presents error alert that can be explicitly bypassed by user when sideloading apps with undeclared permissions, and also allows user to view all undeclared permissions.
This commit is contained in:
Riley Testut
2023-05-22 15:02:26 -05:00
committed by Magesh K
parent e8f676b10b
commit 2afaf73fc5
2 changed files with 64 additions and 10 deletions

View File

@@ -63,7 +63,7 @@ public extension NSManagedObjectContext
public extension UIViewController
{
@MainActor
func presentAlert(title: String, message: String, action: UIAlertAction? = nil) async
func presentAlert(title: String, message: String?, action: UIAlertAction? = nil) async
{
let action = action ?? .ok
@@ -79,19 +79,33 @@ public extension UIViewController
@MainActor
func presentConfirmationAlert(title: String, message: String, primaryAction: UIAlertAction, cancelAction: UIAlertAction? = nil) async throws
{
_ = try await self.presentConfirmationAlert(title: title, message: message, actions: [primaryAction], cancelAction: cancelAction)
}
@MainActor
func presentConfirmationAlert(title: String, message: String, actions: [UIAlertAction], cancelAction: UIAlertAction? = nil) async throws -> UIAlertAction
{
let cancelAction = cancelAction ?? .cancel
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
let action = try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<UIAlertAction, Error>) in
let alertController = UIAlertController(title: title, message: message, preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: cancelAction.title, style: cancelAction.style) { _ in
continuation.resume(throwing: CancellationError())
})
alertController.addAction(UIAlertAction(title: primaryAction.title, style: primaryAction.style) { _ in
continuation.resume()
})
for action in actions
{
alertController.addAction(UIAlertAction(title: action.title, style: action.style) { alertAction in
// alertAction is different than the action provided,
// so return original action instead for == comparison.
continuation.resume(returning: action)
})
}
self.present(alertController, animated: true)
}
return action
}
}