How do I open phone settings when a button is clicked?
Using UIApplication.openSettingsURLString
Update for Swift 5.1
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: UIApplication.openSettingsURLString) 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)
}
Swift 4.2
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)
}
How to open Settings of Android Phone on a button click in our Android App
this should do it
startActivityForResult(new Intent(android.provider.Settings.ACTION_SETTINGS), 0);
starts settings activity for result
Going to Phone Settings when a button is clicked
The solution is to add
startActivityForResult(new Intent(Settings.ACTION_LOCALE_SETTINGS),0);
to your button's function or OnClick event.
Open phone settings when button is clicked in my app
Swift 3 iOS 10
let settingsUrl = NSURL(string:UIApplicationOpenSettingsURLString) as! URL
UIApplication.shared.open(settingsUrl, options: [:], completionHandler: nil)
SwiftUI: How do I open the (App-)phone settings when I push a Button?
Based on this, you can use the following sample code:
import SwiftUI
struct ContentView: View {
var body: some View {
Button(action: {self.settingsOpener()} ){
Text("Open Settings")
}
}
private func settingsOpener(){
if let url = URL(string: UIApplication.openSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
}
}
Android Studio: I want my button to open the phone settings
You need to start a new Intent
. Here is an example to open the Wifi settings:
startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
You get go through the android.provider.Settings
constants for different settings that you can go to.
Hope this helps.
How to open your app in Settings iOS 11
Here is the code you're looking for, I guess:
if let url = URL(string: UIApplicationOpenSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
And in addition, the updated version for swift 5 :
if let url = URL(string: UIApplication.openSettingsURLString) {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}
React Native: How to open OS settings in Android and iOS?
Did you try to use Linking component form react-native (v0.60+)?
import { Button, Linking } from "react-native";
const Screen = () => (
<Button
title="Open Settings"
onPress={() => {
Linking.openSettings();
}}
/>
);
How to open Settings programmatically like in Facebook app?
You can't, there is no API call to do this.
Only system dialogs, dialogs from Apple Frameworks, can open the settings app.
In iOS 5 there was a app url scheme to open the system dialog but Apple removed it later.
With the coming of iOS 8 you can open the settings dialog on your apps page.
if (&UIApplicationOpenSettingsURLString != NULL) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
else {
// Present some dialog telling the user to open the settings app.
}
Related Topics
How to Change the Status Bar Background Color and Text Color on iOS 7
Change Paid App to Free But Know If User Previously Purchased It
How to Hide Keyboard When Using Swiftui
How to Get My Ip Address Programmatically on Ios/Macos
Ios App Submission: Missing 64-Bit Support
How to Download Multiple Files Sequentially Using Nsurlsession Downloadtask in Swift
Passing Data With Unwind Segue
How to Produce an Effect Similar to the iOS 7 Blur View
Draw Text Along Circular Path in Swift For Ios
Can't Get Correct Value of Keyboard Height in Ios8
Iphone Navigation Bar Title Text Color
Multiple Lines of Text in Uilabel
Redirect to Application If Installed, Otherwise to App Store