2019. 2. 4. 15:30

7.0에서 되길래 별 생각 없이 프로덕션으로 올렸는데 8.0유저들이 알림 안 온다고 합니다 ㅡ.-;;;

 

그래서 빌드를 돌리니....

잘쓰던 코드가 업데이트하고 나니 오류가 납니다.

Unhandled Exception:


Java.Lang.NoSuchMethodError: <Timeout exceeded getting exception details>

 


알림이 뭐 어쨌다고??????

 

1. 안드로이드 알림이 바뀌었다.

 

안드로이드 오래오(8.0, Oreo) 버전부터 알림의 구조가 좀 바뀌면서 자마린도 업데이트가 있었습니다.

어찌 됐건 오래오 버전부터는 'Notification.Builder'를 사용해야 합니다.

 

2. 오래오 미만버전에서는 안된다

'Notification.Builder'로 바꾸고 나니 이제 오래오 미만 버전에서 오류가 납니다 ㅋㅋㅋㅋ


MSDN을 보다가 뭔가 다른 걸 발견했습니다.

(참고 : 연습-Xamarin.Android에서 로컬 알림 사용 )


알림을 생성할 때 'NotificationCompat'를 사용하네?

참조를 확인했더니.....



아......

이전버전 안드로이드는 'Android.Support.V4.App'를 참조하여 알림을 처리합니다.

그래서 오래오 미만은 'NotificationCompat.Builder'

오래오 이상은 'Notification.Builder'를 사용해야 합니다.

 

3. 버전별로 나누기

위와 같은 문제 때문에 버전별로 나누는 작업을 해줘야 합니다.

 

'Build.VERSION.SdkInt'로 안드로이드 버전을 가지고 올 수 있으니 처리해주면 됩니다.

아래는 예시입니다.

 

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
if (Build.VERSION.SdkInt < BuildVersionCodes.O)
{//오래오 미만
    NotificationCompat.Builder notificationBuilder2 
        = new NotificationCompat.Builder(MainActivity.activity, GlobalStatic.FCM_Channel);
    notificationBuilder2.SetSmallIcon(Resource.Drawable.OnulWare);
    notificationBuilder2.SetContentTitle(message.GetNotification().Title);
    notificationBuilder2.SetContentText(message.GetNotification().Body);
    notificationBuilder2.SetAutoCancel(true);
    notificationBuilder2.SetContentIntent(pendingIntent);
 
 
    NotificationManager notificationManager = NotificationManager.FromContext(this);
    //알람을 띄우고 카운터를 늘려 다음 알람을 중첩되지 않게 한다.
    notificationManager.Notify(GlobalStatic.PushAlarmCount, notificationBuilder2.Build());
}
else
{//오래오 이상
    Notification.Builder notificationBuilder2 
        = new Notification.Builder(MainActivity.activity, GlobalStatic.FCM_Channel);
    notificationBuilder2.SetSmallIcon(Resource.Drawable.OnulWare);
    notificationBuilder2.SetContentTitle(message.GetNotification().Title);
    notificationBuilder2.SetContentText(message.GetNotification().Body);
    notificationBuilder2.SetAutoCancel(true);
    notificationBuilder2.SetContentIntent(pendingIntent);
 
 
    NotificationManager notificationManager = NotificationManager.FromContext(this);
    //알람을 띄우고 카운터를 늘려 다음 알람을 중첩되지 않게 한다.
    notificationManager.Notify(GlobalStatic.PushAlarmCount, notificationBuilder2.Build());
}
cs

 

'O'버전 미만은 'NotificationCompat.Builder'을 사용합니다.

 

 

마무리

크로스 플랫폼 프래임웍을 사용하면 이런 일을 비일비재 합니다.

개발사가 얼마나 빠르게 대응해주냐가 중요한 거죠.

그런 면에서 자마린은 대응이 빨라서 좋긴한데.....가끔 치명적인 버그가 1년씩 고쳐지지 않는 경우도 있습니다 ㅜㅡ

 

어찌 됐건 재가 쓴 포스팅 리스트를 보면 아이폰 쪽에 이런 글이 많은 편인데 이번엔 안드로이드였습니다 ㅎㅎㅎ