更新代码

This commit is contained in:
2024-09-05 22:04:41 +08:00
parent e371cd9e47
commit fda6fe4dcf
19 changed files with 800 additions and 179 deletions

View 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)
}
})
}
}