消息设置

This commit is contained in:
huangshijie 2024-06-08 04:21:36 +08:00
parent 379cff4c73
commit 6de662fea4
4 changed files with 102 additions and 2 deletions

View File

@ -8,6 +8,7 @@
/* Begin PBXBuildFile section */
62822D34C11155CAA24AED5D /* libPods-copinism.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B7CC5A49B6747B08B414B26 /* libPods-copinism.a */; };
DE316D982C1397900025EFC1 /* MessageSetting.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE316D972C1397900025EFC1 /* MessageSetting.swift */; };
DE9C3A152C0E390200951DEE /* Api.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9C39E62C0E390200951DEE /* Api.swift */; };
DE9C3A162C0E390200951DEE /* Req.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9C39E72C0E390200951DEE /* Req.swift */; };
DE9C3A172C0E390200951DEE /* Target.swift in Sources */ = {isa = PBXBuildFile; fileRef = DE9C39E82C0E390200951DEE /* Target.swift */; };
@ -48,6 +49,7 @@
5F7481AB0860E088E65A7C67 /* Pods-copinism.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-copinism.debug.xcconfig"; path = "Target Support Files/Pods-copinism/Pods-copinism.debug.xcconfig"; sourceTree = "<group>"; };
6D62068149B853380AA60DA2 /* Pods-copinism.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-copinism.release.xcconfig"; path = "Target Support Files/Pods-copinism/Pods-copinism.release.xcconfig"; sourceTree = "<group>"; };
DE29445B2C0E21760098481D /* copinism.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = copinism.app; sourceTree = BUILT_PRODUCTS_DIR; };
DE316D972C1397900025EFC1 /* MessageSetting.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageSetting.swift; sourceTree = "<group>"; };
DE9C39E62C0E390200951DEE /* Api.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Api.swift; sourceTree = "<group>"; };
DE9C39E72C0E390200951DEE /* Req.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Req.swift; sourceTree = "<group>"; };
DE9C39E82C0E390200951DEE /* Target.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Target.swift; sourceTree = "<group>"; };
@ -210,6 +212,7 @@
children = (
DE9C3A012C0E390200951DEE /* MessageDetail.swift */,
DE9C3A022C0E390200951DEE /* MessageView.swift */,
DE316D972C1397900025EFC1 /* MessageSetting.swift */,
);
path = Message;
sourceTree = "<group>";
@ -424,6 +427,7 @@
DE9C3A312C0E390200951DEE /* ContentView.swift in Sources */,
DE9C3A2D2C0E390200951DEE /* RecordView.swift in Sources */,
DE9C3A292C0E390200951DEE /* Login.swift in Sources */,
DE316D982C1397900025EFC1 /* MessageSetting.swift in Sources */,
DE9C3A2E2C0E390200951DEE /* ShoppingView.swift in Sources */,
DE9C3A2C2C0E390200951DEE /* TargetItamSwift.swift in Sources */,
DE9C3A362C10AA8000951DEE /* MessageBack.swift in Sources */,

View File

@ -20,14 +20,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
//
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in
var notify = false
if granted {
DispatchQueue.main.async {
application.registerForRemoteNotifications()
}
notify = true
} else {
// 使
print("用户拒绝通知权限: \(String(describing: error))")
}
UserDefaults.standard.set(notify, forKey: "notify")
}
return true
}

View File

@ -0,0 +1,84 @@
//
// MessageSetting.swift
// copinism
//
// Created by on 2024/6/8.
//
import SwiftUI
struct MessageSettingsView: View {
@State private var isNotificationEnabled = false
@State private var isSpamFilterEnabled = false
@State private var isDiscussionEnabled = false
var body: some View {
NavigationView {
Form {
if isNotificationEnabled {
Section(header: Text("消息设置")) {
NavigationLink(destination: Text("接受消息通知")) {
Text("接受消息通知")
Spacer()
Text("已开启")
.font(.subheadline)
.foregroundColor(.gray)
}
}
} else {
Section(header: Text("消息设置")) {
VStack(alignment: .leading) {
Text("消息通知已关闭")
.font(.headline)
.padding(.bottom, 2)
Text("你已在系统中关闭通知。点击「去开启」前往系统设置-通知中,打开「允许通知」")
.font(.subheadline)
.foregroundColor(.gray)
Button(action: {
if let appSettings = URL(string: UIApplication.openSettingsURLString) {
UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)
}
}) {
Text("去开启")
.foregroundColor(.blue)
}
}
.padding()
}
}
Section(header: Text("消息通知设置")) {
Toggle(isOn: $isSpamFilterEnabled) {
Text("一键免打扰")
Spacer()
Text("只接收xxxx消息")
.font(.subheadline)
.foregroundColor(.gray)
}
Toggle(isOn: $isDiscussionEnabled) {
Text("讨论消息")
Spacer()
Text("(讨论回复、点赞等)")
.font(.subheadline)
.foregroundColor(.gray)
}
}
}
.navigationTitle("消息设置")
.navigationBarTitleDisplayMode(.inline)
.onAppear() {
isNotificationEnabled = UserDefaults.standard.bool(forKey: "notify")
NotificationCenter.default.addObserver(forName: UIApplication.willEnterForegroundNotification, object: nil, queue: .main) { _ in
isNotificationEnabled = UserDefaults.standard.bool(forKey: "notify")
}
}
.onDisappear() {
NotificationCenter.default.removeObserver(self, name: UIApplication.willEnterForegroundNotification, object: nil)
}
}
}
}
#Preview {
MessageSettingsView()
}

View File

@ -5,13 +5,13 @@
import SwiftUI
import Kingfisher
struct MessageView: View {
@ObservedObject private var viewModel = UserProfileViewModel.shared
@State private var selectedMessage: String?
@State private var selectedSender: String?
@State private var selectedTimestamp: String?
@State private var isDetailViewActive = false
@State private var isSettingsViewActive = false
@State private var messages: [Message] = [
Message(text: "发来了条消息", sender: "系统消息", timestamp: "4:00 PM", isSelf: false, avatar: "https://s3.hcpp.top/avatar/ORTPJkyqeULR/%E9%BB%84%E5%AF%8C%E8%B4%B5/1709263869_avatar.jpg?e=1717342975&token=DhKKj58tWve-b3U6BMyFGVUdZ78NXqs4mUhnPaZq:IsdKBn2Kyovp4haD0IQMAKrE6oA=", num: 9),
]
@ -26,6 +26,12 @@ struct MessageView: View {
Button(action: addNewMessage) {
Image(systemName: "plus")
}
Spacer()
Button(action: {
isSettingsViewActive = true
}) {
Image(systemName: "gearshape.fill")
}
}
.padding()
@ -85,7 +91,9 @@ struct MessageView: View {
.navigationDestination(isPresented: $isDetailViewActive) {
MessageDetailView()
}
.toolbar(.hidden)
.navigationDestination(isPresented: $isSettingsViewActive) {
MessageSettingsView()
}
}
.onAppear {
requestNotificationPermission()