작성
·
323
0
현재 진도
섹션 7. 유저가 직접 푸시 메세지 보내기(FCM) 다른 사람에게 push 날리기 부분까지 수강하였습니다.
문제
구글에서 보내는 알람 (매칭이 되었습니다.)의 경우는 잘 가는데 서로 간의 push는 강의 내용과 동일한 코드로 작성하고 cache제거, 안드로이드 스튜디오 firebase 설정 까지 다시 하고 log에도 별다른 오류 코드가 뜨지 않습니다... ( 유저삭제, 회원가입새로 , 앱삭제 후 재등록 했습니다..)
깃 레퍼지토르 / build.gradle / mylikelistActivity / notiAPI / NotiModel / PushNotification / Repo / Retrofitinstance 순으로 올립니다.
build.gradle
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'
implementation 'com.squareup.okhttp3:okhttp:3.4.1'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
manifest
<service android:name=".message.fcm.FirebaseService"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
mylistlistActivity (Item 클릭 부분과 함수 private val 부분만 올립니다.)
getMyLikeList()
userListView.setOnItemClickListener { parent, view, position, id ->
checkMatching(likeUserList[position].uid.toString())
val notiModel = NotiModel("ㅁㄴㅇㄻㄴㅇㄹ", "ㅁㄴㅇㄻㄴㅇㄻㄴㅇㄻㄴㅇㄹ")
val pushModel = PushNotification(notiModel,likeUserList[position].token.toString())
Log.d(TAG, likeUserList[position].token.toString())
testPush(pushModel)
}
private fun testPush(notification: PushNotification) = CoroutineScope(Dispatchers.IO).launch {
try {
Log.w(TAG, "testPush작동")
Retrofitinstance.api.postNotification(notification)
} catch (e: Exception) {
Log.w(TAG, "testPush망함")
}
}
notiAPI
interface NotiAPI {
@Headers("Authorization: key=$SERVER_KEY", "Content-Type:$CONTENT_TYPE")
@POST("fcm/send")
suspend fun postNotification(@Body notification: PushNotification): Response<ResponseBody>
}
NotiModel
data class NotiModel (
val title : String = "",
val content : String = "", )
pushnotification
class PushNotification(
val data: NotiModel,
val token: String
)
repo
key값 은 아래 위치에서 받아왔습니다.
class Repo {
companion object {
const val BASE_URL = "https://fcm.googleapis.com"
const val SERVER_KEY = ""
const val CONTENT_TYPE = "application/json"
}
}
retrofitinstance
class Retrofitinstance {
companion object{
private val retrofit by lazy {
Log.d("MyLIkeListActivityTAG", "Retrofitinstance")
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory((GsonConverterFactory.create()))
.build()
}
val api = retrofit.create(NotiAPI::class.java)
}
}
올려주신 소스코드와 비교해 봤는데 제가 놓친 오타나 다른 부분이 있는지,,, 아니면 다른 추천 하실만한 방법이 있는지 문의드립니다...!
답변 1
0
안녕하세요, 인프런 AI 인턴이에요. push알림이 전달되지 않는 문제에 대해 답변드릴게요.
push알림이 전달되지 않는 경우에는 몇 가지 원인이 있을 수 있습니다. 먼저, 코드와 설정이 올바르게 구성되어 있는지 확인해보셔야 합니다. 다음으로, 단말기에 해당 앱의 알림 권한이 허용되어 있는지 확인해보세요. 또한, FCM 서버에 등록된 토큰과 단말기에 설치된 앱의 토큰이 일치하는지 확인해야 합니다.
이 문제를 해결하기 위해 몇 가지 디버깅 단계를 거쳐볼 수 있습니다. 먼저, 로그를 확인하여 어떤 오류가 발생하는지 확인해보세요. 또한, FCM 메시지를 보내는 함수를 호출할 때 올바른 파라미터를 전달하고 있는지도 확인해야 합니다.
그리고 마지막으로, FCM 서버에서 제공하는 디버깅 도구를 사용하여 문제를 해결할 수도 있습니다. FCM 서버의 설정이나 푸시 메시지 전송 과정에서 문제가 발생할 수 있으므로, 해당 도구를 사용하여 자세한 정보를 얻을 수 있습니다.
만약 위의 조치를 취해도 문제가 해결되지 않는다면, 인프런 고객센터나 해당 강의의 Q&A를 통해 문의해보시는 것을 권장드립니다. 강의 내용과 관련된 질문이라면 더 정확하고 신속한 답변을 받으실 수 있을 거예요. 좋은 결과 있기를 바래요!