Skip to content

Instantly share code, notes, and snippets.

@nqmgaming
Created September 16, 2025 02:14
Show Gist options
  • Select an option

  • Save nqmgaming/80c4fa8827d2686409eed2d8fc87f69e to your computer and use it in GitHub Desktop.

Select an option

Save nqmgaming/80c4fa8827d2686409eed2d8fc87f69e to your computer and use it in GitHub Desktop.
//
// ContentView.swift
// openbattery
//
// Created by Nguyen Quang Minh on 15/9/25.
//
import SwiftUI
struct ContentView: View {
var body: some View {
VStack(spacing: 12) {
Image(systemName: "battery.100")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
Button("Open Battery") {
SettingsHelper.shared.openSettings(.wifiSettings) { ok in
print("Open")
}
}
.buttonStyle(.borderedProminent)
}
.padding()
}
}
#Preview {
ContentView()
}
//
// SettingsHelper.swift
// batteryZz
//
// Created by Nguyen Quang Minh on 15/9/25.
//
import UIKit
class SettingsHelper {
static let shared = SettingsHelper()
private init() {}
enum SettingsType {
case appSettings
case notificationSettings
case microfonSettings
case cameraSettings
case locationSettings
case photosSettings
case siriSettings
case wifiSettings
case bluetoothSettings
case cellularSettings
case batterySettings
case privacySettings
var urlString: String {
switch self {
case .appSettings: return UIApplication.openSettingsURLString
case .notificationSettings:
if #available(iOS 16.0, *) {
return UIApplication.openNotificationSettingsURLString
} else {
return UIApplication.openSettingsURLString
}
case .microfonSettings: return "App-Prefs:Privacy&path=MICROPHONE"
case .cameraSettings: return "App-Prefs:Privacy&path=CAMERA"
case .locationSettings: return "App-Prefs:Privacy&path=LOCATION"
case .photosSettings: return "App-Prefs:Privacy&path=PHOTOS"
case .siriSettings: return "App-Prefs:SIRI"
case .wifiSettings: return "App-Prefs:WIFI"
case .bluetoothSettings: return "App-Prefs:Bluetooth"
case .cellularSettings: return "App-Prefs:MOBILE_DATA_SETTINGS_ID"
case .batterySettings: return "App-Prefs:BATTERY_USAGE"
case .privacySettings: return "App-Prefs:Privacy"
}
}
}
func openSettings(_ type: SettingsType, completion: @escaping (Bool) -> Void) {
guard let url = URL(string: type.urlString) else {
print("Invalid settings URL")
completion(false)
return
}
UIApplication.shared.open(url) { success in
if success {
print("Successfully opened settings: \(type)")
} else {
print("Failed to open settings: \(type)")
}
completion(success)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment