feat: yangshi
This commit is contained in:
parent
b1cd957d0c
commit
55255bf0f8
@ -26,19 +26,23 @@ struct PermissionManagementView: View {
|
|||||||
// 1. 相册权限
|
// 1. 相册权限
|
||||||
PermissionRow(
|
PermissionRow(
|
||||||
title: "Gallery Permissions",
|
title: "Gallery Permissions",
|
||||||
isEnabled: photoLibraryStatus == .authorized
|
isEnabled: photoLibraryStatus == .authorized,
|
||||||
) {
|
action: {
|
||||||
requestPhotoLibraryPermission()
|
requestPhotoLibraryPermission()
|
||||||
}
|
},
|
||||||
|
openSettings: openAppSettings
|
||||||
|
)
|
||||||
.background(Color.white)
|
.background(Color.white)
|
||||||
|
|
||||||
// 2. 通知权限
|
// 2. 通知权限
|
||||||
PermissionRow(
|
PermissionRow(
|
||||||
title: "Notification Permissions",
|
title: "Notification Permissions",
|
||||||
isEnabled: notificationStatus == .authorized
|
isEnabled: notificationStatus == .authorized,
|
||||||
) {
|
action: {
|
||||||
requestNotificationPermission()
|
requestNotificationPermission()
|
||||||
}
|
},
|
||||||
|
openSettings: openAppSettings
|
||||||
|
)
|
||||||
.background(Color.white)
|
.background(Color.white)
|
||||||
}
|
}
|
||||||
.background(Color.white)
|
.background(Color.white)
|
||||||
@ -122,9 +126,11 @@ struct PermissionManagementView: View {
|
|||||||
|
|
||||||
/// 打开应用设置页面
|
/// 打开应用设置页面
|
||||||
private func openAppSettings() {
|
private func openAppSettings() {
|
||||||
if let url = URL(string: UIApplication.openSettingsURLString) {
|
guard let settingsUrl = URL(string: UIApplication.openSettingsURLString),
|
||||||
UIApplication.shared.open(url)
|
UIApplication.shared.canOpenURL(settingsUrl) else {
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
UIApplication.shared.open(settingsUrl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,6 +139,14 @@ struct PermissionRow: View {
|
|||||||
let title: String // 权限名称
|
let title: String // 权限名称
|
||||||
let isEnabled: Bool // 是否已授权
|
let isEnabled: Bool // 是否已授权
|
||||||
let action: () -> Void // 点击事件
|
let action: () -> Void // 点击事件
|
||||||
|
let openSettings: () -> Void // 打开设置页面的函数
|
||||||
|
|
||||||
|
init(title: String, isEnabled: Bool, action: @escaping () -> Void, openSettings: @escaping () -> Void) {
|
||||||
|
self.title = title
|
||||||
|
self.isEnabled = isEnabled
|
||||||
|
self.action = action
|
||||||
|
self.openSettings = openSettings
|
||||||
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button(action: action) {
|
Button(action: action) {
|
||||||
@ -145,18 +159,23 @@ struct PermissionRow: View {
|
|||||||
Spacer()
|
Spacer()
|
||||||
|
|
||||||
// 权限开关
|
// 权限开关
|
||||||
Toggle("", isOn: .constant(isEnabled))
|
Toggle("", isOn: .init(
|
||||||
.labelsHidden()
|
get: { isEnabled },
|
||||||
.tint(Color.themePrimary)
|
set: { newValue in
|
||||||
.disabled(true)
|
// 打开系统设置
|
||||||
.onAppear {
|
openSettings()
|
||||||
// 使用主题色并确保完全不透明
|
|
||||||
let themeColor = UIColor(Color.themePrimary)
|
|
||||||
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).onTintColor = themeColor
|
|
||||||
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).thumbTintColor = .white
|
|
||||||
// 确保使用不透明的背景
|
|
||||||
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).backgroundColor = UIColor.clear
|
|
||||||
}
|
}
|
||||||
|
))
|
||||||
|
.labelsHidden()
|
||||||
|
.tint(Color.themePrimary)
|
||||||
|
.onAppear {
|
||||||
|
// 使用主题色并确保完全不透明
|
||||||
|
let themeColor = UIColor(Color.themePrimary)
|
||||||
|
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).onTintColor = themeColor
|
||||||
|
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).thumbTintColor = .white
|
||||||
|
// 确保使用不透明的背景
|
||||||
|
UISwitch.appearance(whenContainedInInstancesOf: [UIView.self]).backgroundColor = UIColor.clear
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.padding()
|
.padding()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user