I´m new in SwiftUI. I want to know how can I open the App Settings in the Setting App from the iPhone, when the user push a Button in the App.
Asked
Active
Viewed 1,513 times
-1
-
2Does this answer your question? [How do I open phone settings when a button is clicked?](https://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked) – pawello2222 Oct 02 '20 at 21:05
-
No that's in Swift, but I need something in SwiftUI – lula08 Oct 02 '20 at 21:08
-
2SwiftUI is only a Swift framework. What you write in SwiftUI Button's `action` is pure Swift. – pawello2222 Oct 02 '20 at 21:15
-
Ahh Okay thanks. I will try it. – lula08 Oct 02 '20 at 21:39
1 Answers
4
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)
}
}
}
}

Khashayar
- 357
- 3
- 12