1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import Foundation
- import UIKit
- struct Alert {
-
- static func showAlert(on vc:UIViewController, with title:String, message:String) {
- let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
- alert.addAction(UIAlertAction(title: AppConstant.Ok, style: .default, handler: nil))
- DispatchQueue.main.async {
- vc.present(alert, animated: true, completion: nil)
- }
- }
-
- static func showAlertWithAction(vc:UIViewController,
- title: String,
- message: String,
- alertStyle:UIAlertController.Style,
- actionTitles:[String],
- actionStyles:[UIAlertAction.Style],
- actions: [((UIAlertAction) -> Void)]){
-
- let alertController = UIAlertController(title: title, message: message, preferredStyle: alertStyle)
- for(index, indexTitle) in actionTitles.enumerated(){
- let action = UIAlertAction(title: indexTitle, style: actionStyles[index], handler: actions[index])
- alertController.addAction(action)
- }
- DispatchQueue.main.async {
- vc.present(alertController, animated: true, completion: nil)
- }
- }
-
-
-
- static func showInternetFailureAlert(on vc:UIViewController){
- showAlertWithAction(vc: vc, title: AppConstant.internetAlertTitle, message: AppConstant.internetAlertMessage, alertStyle: .alert, actionTitles: ["Cancel", "Open Setting"], actionStyles: [.cancel, .default], actions: [
- {_ in
- print("cancel click")
- },
- {_ in
- if let url = URL.init(string: UIApplication.openSettingsURLString) {
- UIApplication.shared.open(url, options: [:], completionHandler: nil)
- }
- }
- ])
- }
-
- static func showInvalidAlert(on vc:UIViewController){
- showAlert(on: vc, with: AppConstant.defaultTitle, message: AppConstant.defaultMsg)
- }
-
- }
|