Skip to content
This repository was archived by the owner on Jan 31, 2024. It is now read-only.
This repository was archived by the owner on Jan 31, 2024. It is now read-only.

FCM 전송 데이터 추가 #22

@hoyahozz

Description

@hoyahozz

목적

FCM 전송 데이터 추가

개요

  • 안드로이드에서 Data 단만 사용하여 처리하려 했으나 안드로이드 상의 여러 이슈로 인해 실패........
  • 대표적인 예로 사용자가 강제로 앱을 종료할 경우 알람이 오지 않는 버그가 있는데, 이럴 때 카카오등의 회사는 어떻게 대처하는지 알아봤더니...
    • 삼성에서 직접 WhiteList 로 등록된 앱만이 강제로 종료돼도 메세지를 지속적으로 받을 수 있다는 것.....
    • 출처 : https://blog.voidmainvoid.net/157
  • 그런 이유로, Notification - Data 모두를 받아야 정상적으로 처리가 가능할 것으로 보임.....
  • 현재까지 실제로 작성해본 테스트 코드는 아래와 같음......
  • Data 단만 사용하더라도 정상 작동하는 것을 확인(22.08.09)
def send_to_firebase_cloud_messaging():
    topic = 'corona'
    major_code = 301
    department = ''
    krTopic = ''
    
    if(major_code == 301) : 
        department = '컴퓨터소프트웨어공학과'
        
    if(topic == 'corona') : 
        krTopic = '코로나19'
    
    message = messaging.Message(
        notification=messaging.Notification(
            title = '키워드 알림이 도착했어요!',
            body = '코로나19(이)가 포함된 공지사항이 컴퓨터소프트웨어공학과에 올라왔어요!',
        ),
        data={
            'department': department,
            'num': '120',
            'title' :'[코로나19] 확진자 발생 및 검사시행 안내',
            'keyword' : topic
        },
        
        topic = topic,
    )

    response = messaging.send(message)
    print('Successfully sent message:', response)


send_to_firebase_cloud_messaging()
  • 보면 알겠지만, Notification 단에 데이터가 모두 매핑되어 들어간 것을 확인할 수 있음.

기능

  • 알람 데이터를 넣기 위해 major_code 가 301일 경우 컴퓨터소프트웨어공학과 로 매핑하는 처리를 거쳐야 함.
  • 또한, keyword 역시 실제 메세지 데이터로 매핑하는 처리가 필요함.
  • 즉, ("${keyword}(이)가 포함된 공지사항이 ${department}에 올라왔어요!") 의 형식으로 매핑해야 함.

참고

  • 안드로이드에서는 이미 여러 매핑 코드가 있는데, 도움이 되었으면 좋겠음..
fun mapKeywordEnglishToKorean(english: String): String {
    return when (english) {
        "exam" -> "시험"
        "course" -> "수강"
        "lecture" -> "특강"
        "season" -> "계절학기"
        "scholarship" -> "장학"
        "kosaf" -> "국가장학"
        "tuition" -> "등록"
        "leave" -> "휴학"
        "return" -> "복학"
        "graduation" -> "졸업"
        "transfer" -> "전과"
        "drop" -> "학기포기"
        "recruitment" -> "채용"
        "contest" -> "공모전"
        "field" -> "현장실습"
        "competition" -> "대회"
        "service" -> "봉사"
        "dormitory" -> "기숙사"
        "corona" -> "코로나19"
        "club" -> "동아리"
        else -> throw IllegalArgumentException("올바른 타입이 아닙니다.")
    }
}

fun mapDepartmentCodeToKorean(code: Int): String {
    return when (code) {
        CODE.SCHOOL_CODE -> "학교"
        CODE.MECHANICAL_ENGINE_CODE -> "기계공학과"
        CODE.MECHANICAL_DESIGN_CODE -> "기계설계공학과"
        CODE.AUTOMATION_ENGINE_CODE -> "자동화공학과"
        CODE.ROBOT_ENGINE_CODE -> "로봇공학과"
        CODE.COMPUTER_SOFTWARE_ENGINE_CODE -> "컴퓨터소프트웨어공학과"
        CODE.COMPUTER_INFO_ENGINE_CODE -> "컴퓨터정보공학과"
        CODE.ARTIFICIAL_ENGINE_CODE -> "인공지능소프트웨어공학과"
        CODE.ELECTRICAL_ENGINE_CODE -> "전기공학과"
        CODE.INFO_ELECTRONIC_ENGINE_CODE -> "정보전자공학과"
        CODE.SEMICONDUCTOR_ENGINE_CODE -> "반도체전자공학과"
        CODE.INFO_COMMUNICATION_ENGINE_CODE -> "정보통신공학과"
        CODE.BIOCHEMICAL_ENGINE_CODE -> "생명화학공학과"
        CODE.BIO_CONVERGENCE_ENGINE_CODE -> "바이오융합공학과"
        CODE.ARCHITECTURE_CODE -> "건축과"
        CODE.INTERIOR_DESIGN_CODE -> "실내건축디자인과"
        CODE.VISUAL_DESIGN_CODE -> "시각디자인과"
        CODE.BUSINESS_ADMINISTRATION_CODE -> "경영학과"
        CODE.TAX_ACCOUNTING_CODE -> "세무회계학과"
        CODE.DISTRIBUTION_MARKETING_CODE -> "유통마케팅학과"
        CODE.HOTEL_TOURISM_CODE -> "호텔관광학과"
        CODE.MANAGEMENT_INFORMATION_CODE -> "경영정보학과"
        CODE.BIG_DATA_MANAGEMENT_CODE -> "빅데이터경영과"
        else -> throw IllegalArgumentException("올바른 타입이 아닙니다.")
    }
}

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions