[英]How to get the device token from laravel to send push notification?
I'm new to laravel and I want to send a push notification to my android and ios device.我是 laravel 的新手,我想向我的 android 和 ios 设备发送推送通知。 I know how to send push notification but I don't know how to get the device token.我知道如何发送推送通知,但我不知道如何获取设备令牌。
I use:"davibennun/laravel-push-notification" https://github.com/davibennun/laravel-push-notification to send pushnotification我使用:“davibennun/laravel-push-notification” https://github.com/davibennun/laravel-push-notification发送pushnotification
In your class that extends FirebaseMessagingService Service in onNewToken method send the new token to the back-end and store it in database and whenever you wan't to send notification through backend(laravel) use that token...在您的 class 中,在 onNewToken 方法中扩展 FirebaseMessagingService 服务,将新令牌发送到后端并将其存储在数据库中,每当您不想通过后端(laravel)发送通知时,请使用该令牌...
public class MyFirebaseMessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
...
}
@Override
public void onNewToken(@NonNull String token) {
super.onNewToken(token);
sendTokenToServer(token);
}
private void sendTokenToServer(String token) {
//Send it to server using retrofit or any other lib that you're familiar with
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.