【问题标题】:How to get the device token from laravel to send push notification?如何从 laravel 获取设备令牌以发送推送通知?
【发布时间】:2020-05-23 16:40:18
【问题描述】:

我是 laravel 的新手,我想向我的 android 和 ios 设备发送推送通知。我知道如何发送推送通知,但我不知道如何获取设备令牌。

【问题讨论】:

  • 您应该为这个问题添加更多上下文。你到底试过什么?你能给我们看看 PHP 代码和/或 Android 代码吗?
  • 你用什么来发送推送通知?

标签: android ios laravel token


【解决方案1】:

我使用 :"davibennun/laravel-push-notification" https://github.com/davibennun/laravel-push-notification 发送推送通知

【讨论】:

    【解决方案2】:

    在 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
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-06
      • 1970-01-01
      • 2016-05-08
      • 2010-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-17
      相关资源
      最近更新 更多