Based on this link, https://stackoverflow.com/a/28152624/743663
you can open ACCESSIBILITY settings, but can I dig into more with URL settings like ACCESSIBILITY->Speech-Voice?
My app uses text to speech, so I want users to go to the voice settings to download enhanced voices easily.
I guess there is no way to download enhanced voices programmatically, so I want to show the settings screen easily at least.
This is the way to open ACCESSIBILITY.
override func viewDidAppear(_ animated: Bool) {
let alertController = UIAlertController (title: "Title", message: "Go to Settings?", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
guard let settingsUrl = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
if UIApplication.shared.canOpenURL(settingsUrl) {
UIApplication.shared.open(settingsUrl, completionHandler: { (success) in
print("Settings opened: \(success)") // Prints true
})
}
}
alertController.addAction(settingsAction)
let cancelAction = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alertController.addAction(cancelAction)
present(alertController, animated: true, completion: nil)
}
I tried "App-Prefs:root=General&path=ACCESSIBILITY&#path=SPEECH", but it didn't work.
swift 5: ios 13
try this:- App-prefs:root=General&path=ACCESSIBILITY/VOICEOVER/Speech
work for me
Related
When downloading completed I'm showing the alert that download has been completed after that when user click on dismiss button in alert popup self.quickLook(url: url) func will call.
But not showing the file in webView. When removing the alert code everything working fine and file opening in webView.
func showAlerts(){
let alertController = UIAlertController(title: "Download", message: "Download Completed", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "dismiss", style: .default, handler: { _ in
self.dismiss(animated: true, completion: nil)
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(alertController, animated: true, completion: nil)
}
#IBAction func openDoc(_ sender: UIButton) {
if let url = URL(string: "https://ikddata.ilmkidunya.com/images/books/12th-class-chemistry-chapter-10.pdf") {
self.loadFileAsync(url: url) { response, error in
if error == nil {
self.showAlerts()
self.quickLook(url: url)
}
}
}
}
Check console screenshot
Console screenshot see msg
How's your quickLook implemented? I guess it also calls present. You cannot present two things at the same time on iOS.
An option would be to quickLook after the alert is dismissed. Something like:
func showAlerts(and onDismiss: (() -> Void)? = nil) {
let alertController = UIAlertController(title: "Download", message: "Download Completed", preferredStyle: .alert)
alertController.addAction(UIAlertAction(title: "dismiss", style: .default, handler: { _ in
self.dismiss(animated: true) { onDismiss?() }
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
present(alertController, animated: true, completion: nil)
}
#IBAction func openDoc(_ sender: UIButton) {
if let url = URL(string: "https://ikddata.ilmkidunya.com/images/books/12th-class-chemistry-chapter-10.pdf") {
loadFileAsync(url: url) { response, error in
if error == nil {
self.showAlerts { self.quickLook(url: url) }
}
}
}
}
Judging from your words it's exactly what you expect.
My iOS app has been rejected by Apple as the app crashes if a user selected "Dont allow" location access. And the proceeds to tap on my Map button.
How can I wrap this button in check to see if the user has given permission, And if not how can I ask for permission again?
//Map Button Action - Opens Maps - Gives choice of Google or Apple maps
#IBAction func googleMapBtn(_ sender: UIButton) {
UIDevice.current.isBatteryMonitoringEnabled = true
let state = UIDevice.current.batteryState
//If user is in Loop - Cant open maps
if state == .charging {
print("In Loop - Cant open maps")
}
//Present Map Options
else {
let alertController = UIAlertController.init(title: "Open Map", message: "", preferredStyle: .alert)
alertController.addAction(UIAlertAction.init(title: "Google Maps", style: .default, handler: { (action) in
self.googleMapsOpen()
}))
alertController.addAction(UIAlertAction.init(title: "Apple Maps", style: .default, handler: { (action) in
self.appleMapsOpen()
}))
alertController.addAction(UIAlertAction.init(title: "Back", style: .default, handler: { (action) in
self.dismiss(animated: true, completion: nil)
}))
self.present(alertController, animated: true) {
}
}
}
The code crashes whenever a user selects a map type Google/Apple and the self.googleMapsOpen() or self.appleMapsOpen() are executed. Specifically is crashed on the let scheme=
func googleMapsOpen(){
print("Google Maps Pressed")
let scheme = "comgooglemaps://?center=\(LocationManager.sharedInstance.location.coordinate.latitude),\(LocationManager.sharedInstance.location.coordinate.longitude)&zoom=15"
self.open(scheme: scheme)
}
func appleMapsOpen(){
print("Apple Maps Pressed")
let scheme = "http://maps.apple.com/?ll=\(LocationManager.sharedInstance.location.coordinate.latitude),\(LocationManager.sharedInstance.location.coordinate.longitude)&zoom=15"
self.open(scheme: scheme)
}
You can do something like this :
func checkLocationPermissionEnabled()
{
if CLLocationManager.locationServicesEnabled()
{
switch(CLLocationManager.authorizationStatus())
{
case .notDetermined, .restricted, .denied:
self.openDeviceLocationSetting()
return
case .authorizedAlways, .authorizedWhenInUse:
//do whatever you want to do with location
return
}
}
else
{
self.openDeviceLocationSetting()
return
}
}
func openDeviceLocationSetting()
{
let alertController = UIAlertController(title: "", message:"For best results, let your device turn on location using Google's location service.", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.default) {
UIAlertAction in
self.isAlertShowing = false
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
if let url = settingsUrl {
UIApplication.shared.openURL(url as URL)
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.default) {
UIAlertAction in
}
alertController.addAction(okAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
}
I have created my code for the authorizations of photos and camera but fore some reason the code runs but never is displayed in the privacy settings. I am clearly missing something but I'm been trying to work it out for almost 12 hours and can't find it out. Is there like a checklist that needs for all options to be ticked before the permission shows up in the privacy settings.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if PHPhotoLibrary.authorizationStatus() != PHAuthorizationStatus.Authorized {
PHPhotoLibrary.requestAuthorization({(status: PHAuthorizationStatus) in
let settings = NSURL(string: UIApplicationOpenSettingsURLString)
// Create the alert controller
let alertController = UIAlertController(title: "Access Photos", message: "ClubVIP requires access to your Photos, please enable access in Privacy Settings.", preferredStyle: .Alert)
// Create the actions
let privacySettingsAction = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) {
UIAlertAction in
//Take to Privacy Settings
UIApplication.sharedApplication().openURL(settings!)
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) {
UIAlertAction in
NSLog("")
}
// Add the actions
alertController.addAction(privacySettingsAction)
alertController.addAction(cancelAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
})
}
if AVCaptureDevice.authorizationStatusForMediaType(AVMediaTypeVideo) != AVAuthorizationStatus.Authorized {
let settings = NSURL(string: UIApplicationOpenSettingsURLString)
//let settings = NSURL(string: UIApplicationOpen)
AVCaptureDevice.requestAccessForMediaType(AVMediaTypeVideo, completionHandler: { granted in
if !granted {
// Create the alert controller
let alertController = UIAlertController(title: "Access Camera", message: "Access to your Camera has been denied, please enable access in Privacy Settings.", preferredStyle: .Alert)
// Create the actions
let privacySettingsAction = UIAlertAction(title: "Settings", style: UIAlertActionStyle.Default) {
UIAlertAction in
//Take to Privacy Settings
UIApplication.sharedApplication().openURL(settings!)
}
// Add the actions
alertController.addAction(privacySettingsAction)
// Present the controller
self.presentViewController(alertController, animated: true, completion: nil)
}
})
}
}
I have a UIAlert that notifies the user that they do not have an internet connection and that they need one in order to use the app. As well as letting them dismiss the alert by tapping the ok action I also want to have a action that when tapped takes the user to the settings app.
func displayAlert(title: String, message: String){
var formEmpty = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
formEmpty.addAction((UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
})))
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).
You can navigate to the setting with this code:
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
UIApplication.sharedApplication().openURL(settingsUrl!)
After adding this code in your function your function will look like:
func displayAlert(title: String, message: String){
var formEmpty = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
formEmpty.addAction((UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
//This will call when you press ok in your alertview
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
UIApplication.sharedApplication().openURL(settingsUrl!)
})))
}
For iOS 10, Swift 3:
let alert = UIAlertController(title: "Alert!", message: "your message here", preferredStyle: .alert)
let settingsAction = UIAlertAction(title: "Settings", style: .default) { (_) -> Void in
let settingsUrl = NSURL(string: UIApplicationOpenSettingsURLString)
UIApplication.shared.open(settingsUrl as! URL, options: [:], completionHandler: nil)
alert.addAction(settingsAction)
present(alert, animated: true, completion: nil)
I've got a picture that can be shared through Facebook and Twitter.
If Facebook or Twitter isn't connected with your phone, a UIAlertAction pops up saying you have to connect.
When I click the OK button, I would want to navigate to the settings panel from the iPhone itself and once done it should go back to the app.
How can I do this?
This is the code I have once there has been clicked on the Twitter button to share the picture.
func twitterClicked( sender:UIBarButtonItem ){
if ( SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter)) {
let twitterVC = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
presentViewController(twitterVC, animated: true, completion: {() -> Void in})
twitterVC.setInitialText("Picture shared through code made in Native Development")
twitterVC.addImage(theView.imageView.image)
twitterVC.addURL(NSURL(string: "http://www.devine.be"))
} else {
println("connecteer je twitter")
let alert = UIAlertController(title: "Connect", message: "Connect your twitter", preferredStyle: UIAlertControllerStyle.Alert)
self.presentViewController(alert, animated: true, completion: nil)
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (action) -> Void in
println("Ok geklikt")
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel) { (action) -> Void in
println("Cancel geklikt")
}
alert.addAction(okAction)
alert.addAction(cancelAction)
}
Here is how you can invoke opening Settings:
let okAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default) { (action) -> Void in
let url = NSURL(string: UIApplicationOpenSettingsURLString)
UIApplication.sharedApplication().openURL(url!)
}
After that the user will have to manually return to the application.