Programming/iOS - ObjC
[APNs, Notification] 알림 설정 (iOS8 SDK 변화)
Tez.Park
2014. 10. 16. 15:41
앱을 구현하다가 보면 시스템 알림 설정값을 체크해야 하는 경우들이 있다.
일반적으로 iOS8 이전 SDK 에서는 아래와 같은 방법으로 체크를 하였지만,
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone) {
// 시스템 알림 설정이 꺼져있는 경우
}
else {
// 시스템 알림 설정이 켜져있는 경우.
// UIRemoteNotificationTypeBadge, UIRemoteNotificationTypeSound, UIRemoteNotificationTypeAlert, UIRemoteNotificationTypeNewsstandContentAvailability
// 위의 네가지 경우에 만족하는 상태
}
iOS8 SDK 부터는 enabledRemoteNotificationTypes 이 메서드가 Deprecated 되어 사용할 수 없게 되었다.
이 문제를 수정하기 위해서는 iOS8과 그 이하 버전의 분기를 타야 하고, 변경된 메서드를 아래와 같이 적용해 주어야 한다.
if ([[[[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."] objectAtIndex:0] integerValue] >= 8) {
if([UIApplication sharedApplication].currentUserNotificationSettings.types == UIUserNotificationTypeNone){
// 시스템 알림 설정이 꺼져있는 경우
}
else {
// 시스템 알림 설정이 켜져있는 경우.
// UIUserNotificationTypeBadge, UIUserNotificationTypeSound, UIUserNotificationTypeAlert
// 위의 세가지 경우에 만족하는 상태
}
}
else {
if([UIApplication sharedApplication].enabledRemoteNotificationTypes == UIRemoteNotificationTypeNone){
// 시스템 알림 설정이 꺼져있는 경우
}
else {
// 시스템 알림 설정이 켜져있는 경우.
// UIRemoteNotificationTypeBadge, UIRemoteNotificationTypeSound, UIRemoteNotificationTypeAlert, UIRemoteNotificationTypeNewsstandContentAvailability
// 위의 네가지 경우에 만족하는 상태
}
}
이 문제는 새로운 버전으로 작업을 하면서 크래쉬같이 눈에 보여서 바로 수정할 수 있는 이슈가 아니라 놓치기 쉬운 문제이니 잘 확인해야 할 것 같다.
반응형