Skip to content

Commit

Permalink
Merge pull request #202 from OMZigak/feat/#198-LocalNotification
Browse files Browse the repository at this point in the history
[feat] local notification
  • Loading branch information
hooni0918 committed Jul 17, 2024
2 parents f30d475 + 548d1cb commit be42734
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions KkuMulKum.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
789D73A72C46AF4900C7077D /* KeychainService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 789D73A62C46AF4900C7077D /* KeychainService.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 */; };
Expand Down Expand Up @@ -234,6 +235,7 @@
789D73AC2C46C19500C7077D /* ProfileModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProfileModel.swift; sourceTree = "<group>"; };
789D73AE2C46D99B00C7077D /* GoogleService-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "GoogleService-Info.plist"; sourceTree = "<group>"; };
789D73B02C46DACD00C7077D /* KkuMulKum.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KkuMulKum.entitlements; sourceTree = "<group>"; };
789D73B22C47CC6D00C7077D /* LocalNotificationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalNotificationManager.swift; sourceTree = "<group>"; };
78AED1332C3D951F000AD80A /* NicknameViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameViewController.swift; sourceTree = "<group>"; };
78AED1362C3D98D1000AD80A /* NicknameView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NicknameView.swift; sourceTree = "<group>"; };
78B928682C29402C006D9942 /* KkuMulKum.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = KkuMulKum.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -513,6 +515,14 @@
path = ViewController;
sourceTree = "<group>";
};
789D73B12C47C81400C7077D /* Notification */ = {
isa = PBXGroup;
children = (
789D73B22C47CC6D00C7077D /* LocalNotificationManager.swift */,
);
path = Notification;
sourceTree = "<group>";
};
78AED1322C3D9514000AD80A /* Nickname */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1155,6 +1165,7 @@
DE254AA32C31107C00A4015E /* Resource */ = {
isa = PBXGroup;
children = (
789D73B12C47C81400C7077D /* Notification */,
78BD612D2C456162005752FD /* KeyChain */,
78BD612C2C455680005752FD /* Bundle */,
A3DD9C642C45B30600E58A13 /* Service */,
Expand Down Expand Up @@ -1685,6 +1696,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 /* MockCreateMeetingService.swift in Sources */,
Expand Down
38 changes: 38 additions & 0 deletions KkuMulKum/Resource/Notification/LocalNotificationManager.swift
Original file line number Diff line number Diff line change
@@ -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)")
}
}
}
}

0 comments on commit be42734

Please sign in to comment.