Skip to content

Instantly share code, notes, and snippets.

@yoman07
Last active September 2, 2016 17:06
Show Gist options
  • Save yoman07/bd18199c4f903836912da88330f2ead6 to your computer and use it in GitHub Desktop.
Save yoman07/bd18199c4f903836912da88330f2ead6 to your computer and use it in GitHub Desktop.
Display alert view with settings button
//
// AlertControllerFabric.swift
// Mapa Turystyczna
//
// Created by Roman Barzyczak on 05.04.2016.
//
import Foundation
class AlertHelper {
enum AlertType {
case GPSDenied
}
class func factoryFor(type : AlertType) -> UIAlertController {
var title:String!
var message:String!
let cancelAction:UIAlertAction!
let settingsAction:UIAlertAction!
switch type {
case .GPSDenied:
title = NSLocalizedString("Enter your title here", comment:"" )
message = NSLocalizedString("Enter your message here.", comment:"" )
cancelAction = UIAlertAction(title: NSLocalizedString("Cancel", comment:"" ), style: .Cancel, handler: nil)
settingsAction = UIAlertAction(title: NSLocalizedString("Settings", comment:"" ), style: .Default, handler: { action in
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
})
break
}
let alertController = UIAlertController(title: title, message: message, preferredStyle: .Alert)
alertController.addAction(cancelAction)
alertController.addAction(settingsAction)
return alertController
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment