Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- swift
- cocoapods 설치 오류
- ruby설치
- 스파르타 코딩클럽 내일배움캠프
- 프로그래머스 n의 배수 고르기
- 연산자
- Error installing cocoapods
- 배열 만들기1
- array
- 문자열 붙여서 출력하기
- 프로그래머스 최댓값 만들기(2)
- 프로그래머스 암호 해독
- 프로그래머스 주사위 게임1
- 프로그래머스 배열 만들기1
- continue
- 조건에 맞게 수열 변경하기 3
- n번째 원소까지
- 프로그래머스 n번째 원소까지
- Break
- 문자열 정렬하기 (1)
- 스페인어
- 스파르타코딩캠프
- Til
- 프로그래머스 조건에 맞게 수열 변경하기 3
- 프로그래머스 문자열 붙여서 출력하기
- 주사위 게임1
- 프로그래머스
- 프로그래머스 문자열 정렬하기 (1)
- 객체지향
- 프로그래머스 자동커밋
Archives
- Today
- Total
dev._.note
[TIL] 240215_TIL 본문
푸시 알람 기능
알람기능 설정이 어려워서 애를 많이 먹었는데 알고 보니 대리자 설정을 안 해주어서 그런 거였다.
AppDelegate에서 대리자 설정을 안 해주어 안 뜨는 문제를 해결했다.
AppDelegate에서 UNUserNotificationCenter의 대리자(delegate)를 자신으로 설정
UNUserNotificationCenter.current().delegate = self
실제로 적용한 코드
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// UIWindow 생성 및 초기 ViewController 설정
window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = CustomTabBarController() // 탭바 CustomTabBarController
window?.makeKeyAndVisible()
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
print("Notification permission granted.")
} else {
print("Notification permission denied.")
}
}
return true
}
AppDelegate에서 대리자를 설정해 주고 알람을 적용해 보면 이렇게 허용창이 뜬다.
푸시 알람이 적용된 모습
앱 외부에서도 푸시 알람이 잘 뜬다
푸시알람을 클릭하면 앱화면으로 들어가고 얼럿창이 뜬다.
'TIL (Today I Learned)' 카테고리의 다른 글
[Swift] XCTest란? (0) | 2024.03.05 |
---|---|
[TIL] 240216_TIL (0) | 2024.02.16 |
[TIL] 240208_TIL (0) | 2024.02.09 |
[TIL] 240103_TIL (1) | 2024.01.03 |
[TIL] 231220_TIL (0) | 2023.12.20 |