IOS

IOS8 SDK 알림설정

GUCCI 2015. 1. 19. 15:52

앱을 구현하다가 보면 시스템 알림 설정값을 체크해야 하는 경우들이 있다.

일반적으로 iOS8 이전 SDK 에서는 아래와 같은 방법으로 체크를 하였지만,

1
2
3
4
5
6
7
8
if([UIApplication sharedApplication].enabledRemoteNotificationTypes  == UIRemoteNotificationTypeNone) {
    // 시스템 알림 설정이 꺼져있는 경우
}
else {
    // 시스템 알림 설정이 켜져있는 경우.
    // UIRemoteNotificationTypeBadge, UIRemoteNotificationTypeSound, UIRemoteNotificationTypeAlert, UIRemoteNotificationTypeNewsstandContentAvailability
    // 위의 네가지 경우에 만족하는 상태
}


iOS8 SDK 부터는 enabledRemoteNotificationTypes 이 메서드가 Deprecated 되어 사용할 수 없게 되었다.


이 문제를 수정하기 위해서는 iOS8과 그 이하 버전의 분기를 타야 하고, 변경된 메서드를 아래와 같이 적용해 주어야 한다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if ([[UIDevice currentDevice].systemVersion characterAtIndex:0] >= '8') {
    if([UIApplication sharedApplication].currentUserNotificationSettings.types  == UIUserNotificationTypeNone){
    // 시스템 알림 설정이 꺼져있는 경우
    }
    else {
        // 시스템 알림 설정이 켜져있는 경우.
        // UIUserNotificationTypeBadge, UIUserNotificationTypeSound, UIUserNotificationTypeAlert
        // 위의 세가지 경우에 만족하는 상태
    }
}
else {
    if([UIApplication sharedApplication].enabledRemoteNotificationTypes  == UIRemoteNotificationTypeNone){
        // 시스템 알림 설정이 꺼져있는 경우
    }
    else {
        // 시스템 알림 설정이 켜져있는 경우.
        // UIRemoteNotificationTypeBadge, UIRemoteNotificationTypeSound, UIRemoteNotificationTypeAlert, UIRemoteNotificationTypeNewsstandContentAvailability
        // 위의 네가지 경우에 만족하는 상태
    }
}


이 문제는 새로운 버전으로 작업을 하면서 크래쉬같이 눈에 보여서 바로 수정할 수 있는 이슈가 아니라 놓치기 쉬운 문제이니 잘 확인해야 할 것 같다.