[Swift] App BadgeCount 변경하기



# [Swift] App BadgeCount 변경하기

안녕하세요 __물먹고하자__ 입니다 :)
업무 급한일들 마무리 해놓고, 설전까지 코드 정리하다가 __BadgeCount API deprecated__ 된 걸
확인하고 변경했던 부분 공유드립니다.

간단하니 바로 시작!

---
## 1. UIApplecation applicationIconBadgeNumber
> 💡 <a href="https://developer.apple.com/documentation/uikit/uiapplication/applicationiconbadgenumber" target="_blank">applicationIconBadgeNumber</a> iOS 2.0 ~ iOS 17.0 deprecated
💡 <a href="https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/setbadgecount%28_:withcompletionhandler:%29" target="_blank">setBadgeCount</a> iOS 16.0 이상

<div class="separator" style="clear: both;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1_vLFXQONUyNjuOY7RFX-hf3GZYCm_gJQHfVbuuMBw2ecQ-ALMiszxcb6X1QBWpnClhKJdn0cyMTXA9jC5FwlEUIVG_PX5eFmE8XaOfJVZrY2CJze7wZiAKn6AJOVF243UY-9tXYMcxvTCdRlExD2SecdC83QBlPp481103OXEmnw6i75R4FyJ1SEmsjM/s2086/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202025-01-21%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.40.58.png" style="display: block; padding: 1em 0; text-align: center; "><img alt="" border="0" data-original-height="546" data-original-width="2086" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1_vLFXQONUyNjuOY7RFX-hf3GZYCm_gJQHfVbuuMBw2ecQ-ALMiszxcb6X1QBWpnClhKJdn0cyMTXA9jC5FwlEUIVG_PX5eFmE8XaOfJVZrY2CJze7wZiAKn6AJOVF243UY-9tXYMcxvTCdRlExD2SecdC83QBlPp481103OXEmnw6i75R4FyJ1SEmsjM/s600/%E1%84%89%E1%85%B3%E1%84%8F%E1%85%B3%E1%84%85%E1%85%B5%E1%86%AB%E1%84%89%E1%85%A3%E1%86%BA%202025-01-21%20%E1%84%8B%E1%85%A9%E1%84%8C%E1%85%A5%E1%86%AB%2011.40.58.png" width="600"/></a></div>

``` swift
// 카운트 갱신
let dzBadgeCount:Int = '갱신할 카운트 정보(Int)'

if #available(iOS 16.0, *) {
    UNUserNotificationCenter.current().setBadgeCount(dzBadgeCount)
} else {
    UIApplication.shared.applicationIconBadgeNumber = dzBadgeCount
}

```

---
## 마무리
Objc 소스 부분이였는데, Swift로 변경하기 경고로 deprecated 되었다고 떠서 알게되었습니다.
간단한 부분이지만, 최소 버전이 iOS 15.0 이상이여서 분기처리는 추가하였습니다.

오늘은 이만~

즐거운 코딩 되게요.

끝.


댓글