更新代码
This commit is contained in:
30
app/src/main/java/com/aiosman/riderpro/Messaging.kt
Normal file
30
app/src/main/java/com/aiosman/riderpro/Messaging.kt
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.aiosman.riderpro
|
||||
|
||||
import android.util.Log
|
||||
import com.aiosman.riderpro.data.AccountService
|
||||
import com.aiosman.riderpro.data.AccountServiceImpl
|
||||
import com.google.android.gms.tasks.OnCompleteListener
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
object Messaging {
|
||||
fun InitFCM(scope: CoroutineScope) {
|
||||
val accountService: AccountService = AccountServiceImpl()
|
||||
FirebaseMessaging.getInstance().token.addOnCompleteListener(OnCompleteListener { task ->
|
||||
if (!task.isSuccessful) {
|
||||
Log.w("Pushing", "Fetching FCM registration token failed", task.exception)
|
||||
return@OnCompleteListener
|
||||
}
|
||||
|
||||
// Get new FCM registration token
|
||||
val token = task.result
|
||||
|
||||
// Log and toast
|
||||
Log.d("Pushing", token)
|
||||
scope.launch {
|
||||
accountService.registerMessageChannel(client = "fcm", token)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user