From 0dbc15ca9d345d048615427c06ff32767810f50c Mon Sep 17 00:00:00 2001 From: hooni Date: Wed, 17 Jul 2024 20:55:37 +0900 Subject: [PATCH] =?UTF-8?q?feat/#198=20=EB=A1=9C=EC=BB=AC=EC=95=8C?= =?UTF-8?q?=EB=9E=8C=20manager=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KkuMulKum.xcodeproj/project.pbxproj | 19 ++++++++-- .../LocalNotificationManager.swift | 38 +++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 KkuMulKum/Resource/Notification/LocalNotificationManager.swift diff --git a/KkuMulKum.xcodeproj/project.pbxproj b/KkuMulKum.xcodeproj/project.pbxproj index 2a50094e..df331d06 100644 --- a/KkuMulKum.xcodeproj/project.pbxproj +++ b/KkuMulKum.xcodeproj/project.pbxproj @@ -52,11 +52,12 @@ 789873342C3D1A7B00435E96 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789873312C3D1A7B00435E96 /* LoginView.swift */; }; 789AD4B32C3C0093002E2688 /* SocialLoginResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789AD4B22C3C0093002E2688 /* SocialLoginResponseModel.swift */; }; 789AD4B52C3C0147002E2688 /* ResissueResponseModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789AD4B42C3C0147002E2688 /* ResissueResponseModel.swift */; }; - 789D73AF2C46D99B00C7077D /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */; }; 789D73A72C46AF4900C7077D /* KeychainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73A62C46AF4900C7077D /* KeychainService.swift */; }; 789D73A92C46BBB000C7077D /* PagePromiseSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73A82C46BBB000C7077D /* PagePromiseSegmentedControl.swift */; }; 789D73AB2C46BEFF00C7077D /* ProfileTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73AA2C46BEFF00C7077D /* ProfileTargetType.swift */; }; 789D73AD2C46C19500C7077D /* ProfileModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73AC2C46C19500C7077D /* ProfileModel.swift */; }; + 789D73AF2C46D99B00C7077D /* GoogleService-Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */; }; + 789D73B32C47CC6D00C7077D /* LocalNotificationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73B22C47CC6D00C7077D /* LocalNotificationManager.swift */; }; 78AED1342C3D951F000AD80A /* NicknameViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AED1332C3D951F000AD80A /* NicknameViewController.swift */; }; 78AED1372C3D98D1000AD80A /* NicknameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78AED1362C3D98D1000AD80A /* NicknameView.swift */; }; 78B9286C2C29402C006D9942 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78B9286B2C29402C006D9942 /* AppDelegate.swift */; }; @@ -208,12 +209,13 @@ 789873312C3D1A7B00435E96 /* LoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; 789AD4B22C3C0093002E2688 /* SocialLoginResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SocialLoginResponseModel.swift; sourceTree = ""; }; 789AD4B42C3C0147002E2688 /* ResissueResponseModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResissueResponseModel.swift; sourceTree = ""; }; - 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; - 789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = ""; }; 789D73A62C46AF4900C7077D /* KeychainService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainService.swift; sourceTree = ""; }; 789D73A82C46BBB000C7077D /* PagePromiseSegmentedControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PagePromiseSegmentedControl.swift; sourceTree = ""; }; 789D73AA2C46BEFF00C7077D /* ProfileTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileTargetType.swift; sourceTree = ""; }; 789D73AC2C46C19500C7077D /* ProfileModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileModel.swift; sourceTree = ""; }; + 789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = ""; }; + 789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = ""; }; + 789D73B22C47CC6D00C7077D /* LocalNotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotificationManager.swift; sourceTree = ""; }; 78AED1332C3D951F000AD80A /* NicknameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameViewController.swift; sourceTree = ""; }; 78AED1362C3D98D1000AD80A /* NicknameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameView.swift; sourceTree = ""; }; 78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -468,6 +470,14 @@ path = ViewController; sourceTree = ""; }; + 789D73B12C47C81400C7077D /* Notification */ = { + isa = PBXGroup; + children = ( + 789D73B22C47CC6D00C7077D /* LocalNotificationManager.swift */, + ); + path = Notification; + sourceTree = ""; + }; 78AED1322C3D9514000AD80A /* Nickname */ = { isa = PBXGroup; children = ( @@ -1099,6 +1109,7 @@ DE254AA32C31107C00A4015E /* Resource */ = { isa = PBXGroup; children = ( + 789D73B12C47C81400C7077D /* Notification */, 78BD612D2C456162005752FD /* KeyChain */, 78BD612C2C455680005752FD /* Bundle */, A3DD9C642C45B30600E58A13 /* Service */, @@ -1477,7 +1488,6 @@ DE254AC92C311DC200A4015E /* Pretendard-SemiBold.otf in Resources */, DE254AC42C311DC200A4015E /* Pretendard-ExtraBold.otf in Resources */, 789D73AF2C46D99B00C7077D /* GoogleService-Info.plist in Resources */, - DE254AA52C31131600A4015E /* Color.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1548,6 +1558,7 @@ DE32D1D42C3BFB56006848DF /* UpdateProfileNameModel.swift in Sources */, DE6D4D132C3F14D80005584B /* MeetingMemberCell.swift in Sources */, DDAF1C932C3D6E3D008A37D3 /* PagePromiseViewController.swift in Sources */, + 789D73B32C47CC6D00C7077D /* LocalNotificationManager.swift in Sources */, DE9E18922C3BCC9D00DB76B4 /* SocialLoginRequestModel.swift in Sources */, DE254AA82C3118EA00A4015E /* UIView+.swift in Sources */, DD3976732C41B6C800E2A4C4 /* CreateMeetingService.swift in Sources */, diff --git a/KkuMulKum/Resource/Notification/LocalNotificationManager.swift b/KkuMulKum/Resource/Notification/LocalNotificationManager.swift new file mode 100644 index 00000000..14692283 --- /dev/null +++ b/KkuMulKum/Resource/Notification/LocalNotificationManager.swift @@ -0,0 +1,38 @@ +// +// LocalNotificationManager.swift +// KkuMulKum +// +// Created by 이지훈 on 7/17/24. +// + +import Foundation +import UserNotifications + +class LocalNotificationManager { + + private let notificationCenter = UNUserNotificationCenter.current() + + func requestAuthorization(completion: @escaping (Bool) -> Void) { + notificationCenter.requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in + completion(granted) + } + } + + func scheduleNotification(title: String, body: String, triggerDate: Date) { + let content = UNMutableNotificationContent() + content.title = title + content.body = body + content.sound = .default + + let components = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute], from: triggerDate) + let trigger = UNCalendarNotificationTrigger(dateMatching: components, repeats: false) + + let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger) + + notificationCenter.add(request) { error in + if let error = error { + print("Error scheduling notification: \(error)") + } + } + } +}