공부방/iOS

iOS local notification divide (iOS Local Notification 분리)

soycrab 2019. 7. 9. 20:46

iOS local Notification 알림을 받으면,

알림을 받을때마다 한개씩 덮어씌어져 보이는 경우가 있고, 

낱개로 분리되어 나타나는 경우가 있는데 이는

 

let request = UNNotificationRequest(identifier: "test", content: nContent, trigger: trigger)

identifier 부분 차이 입니다.

 

이부분이 값이 동일하면 계속해서 한개의 푸쉬에 덮어 씌어져 보여지게 되고, 

값이 다르면 나뉘어져 보이게 되는데 이부분은 푸쉬가 올때마다 기능에 맞게 다른 값으로 넣어주어 

설정하게 되면 푸쉬가 분리 되어 보이게 됩니다.

 

예를 들어 Badge Number를 가지고 값을 바꾼다 하면 소스 코드는 아래와 같습니다. 

 

Swift Code

        let pushMessage = PushMessage(userInfo)

        let nContent = UNMutableNotificationContent()

        let badgeCount = 1 +  UIApplication.shared.applicationIconBadgeNumber as NSNumber

        nContent.badgebadgeCount

        nContent.title = "test title"

        nContent.body"test body"

        nContent.sound = UNNotificationSound.default

        nContent.userInfo = userInfo

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 0.1, repeats: false)

        let request = UNNotificationRequest(identifier: "test\(badgeCount)", content: nContent, trigger: trigger)

        UNUserNotificationCenter.current().add(request)

 

만약 위 소스코드가 정상적으로 동작하지 않는다면,

iPhone 의 설정이 잘못되어 있을 가능성이 큽니다.

 

설정 -> 하단 스크롤 해서 해당앱 상세 -> 알림 -> 알림 그룹 설정 -> 자동 선택  

만약 끔으로 설정하시면 identifier 를 변경 해도 하나의 알림만 노출하게 됩니다. 

반응형