iOS Uialertview Button to Go to Setting App

iOS UIAlertView button to go to Setting App

For example:

NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"];
[[UIApplication sharedApplication] openURL:url];

And

[font=]
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI`
prefs:root=INTERNET_TETHERING

Open Settings.app When Button is Tapped in UIAlertView on iPhone SDK

iOS 8 and iOS 9

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];


There is no way to do this.

Because till now (11th Jan 2013) there is no url scheme available for settings app.

iOS 6

You can't do this on iOS 6.

iOS 5 and below (< iOS 5.1)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]];

Please refer this answer for more info Call the official *Settings* app from my app on iPhone

Open iOS Email app through UIAlertView button

First, I assume what do you need to add in your code snippet is only this part:

@IBAction func helpfeedbackAlert(_ sender: Any) {

let alertController = UIAlertController(title: "Help & Feedback", message: "text", preferredStyle: .alert)

let cancel = UIAlertAction(title: "Cancel", style: .destructive, handler: nil)

let openEmail = UIAlertAction(title: "Open Email", style: .default, handler: nil)

alertController.addAction(openEmail)
alertController.addAction(cancel)

self.present(alertController, animated: true, completion: nil)
}

Anyway, what do you need is to fill the handler when you create an instance of the UIAlertAction. Referring to the documentation of the init(title:style:handler:):

handler

A block to execute when the user selects the action. This
block has no return value and takes the selected action object as its
only parameter.

So, your openEmail should be like:

let openEmail = UIAlertAction(title: "Open Email", style: .destructive, handler: { (actionSheetController) in
// send your email here...

})

I'm not pretty sure of the mechanism of how do you want to send an email, but I thik you might want to check MFMailComposeViewController, this question should help you to work with it.

Hope it helped.

Adding a action to a UIAlert that takes the user to settings

Use this code . May be help it.

override func viewDidAppear(animated: Bool) {
var alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .Alert)

var settingsAction = UIAlertAction(title: "Settings", style: .Default) { (_) -> Void in
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.sharedApplication().openURL(url)
}
}

var cancelAction = UIAlertAction(title: "Cancel", style: .Default, handler: nil)
alertController.addAction(settingsAction)
alertController.addAction(cancelAction)

presentViewController(alertController, animated: true, completion: nil);
}

Please note UIApplicationOpenSettingsURLString is only available on iOS8.0 and after so if your app should support iOS7 you'll have to check for availability of the constant (or if using Swift 2.0 use the #availability keyword).

How to add an action to a UIAlertView button using Swift iOS

The Swifty way is to use the new UIAlertController and closures:

    // Create the alert controller
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .Alert)

// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) {
UIAlertAction in
NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}

// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)

// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)

Swift 3:

    // Create the alert controller
let alertController = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)

// Create the actions
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
UIAlertAction in
NSLog("OK Pressed")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) {
UIAlertAction in
NSLog("Cancel Pressed")
}

// Add the actions
alertController.addAction(okAction)
alertController.addAction(cancelAction)

// Present the controller
self.present(alertController, animated: true, completion: nil)


Related Topics



Leave a reply



Submit