Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Может обновите информация для FCM? #2

Open
gibigate opened this issue Jan 7, 2019 · 2 comments
Open

Может обновите информация для FCM? #2

gibigate opened this issue Jan 7, 2019 · 2 comments

Comments

@gibigate
Copy link

gibigate commented Jan 7, 2019

В частности хотелось бы узнать, как отправлять badge, image (не icon) и action кнопки для WEB Push

@sanchezzzhak
Copy link

sanchezzzhak commented Jan 7, 2019

https://developers.google.com/web/fundamentals/push-notifications/display-a-notification
https://web-push-book.gauntface.com/demos/notification-examples/

смотрите доку и примеры, параметры добавлять нужно в эту функцию

self.registration.showNotification в виде json объекта 2 аргументом.

self.addEventListener('push', function(event) {
  console.log('Получено push-сообщение', event);
  var data  = event.data.json();  // json данные, которые отправили в из php скрипта ( они могут быть любыми, главное json ).

  var title = 'Ура, работает!';
  var body = 'Было получено сообщение от сайта.';
  var icon = '/icon-192x192.png';
  var tag = 'simple-push-demo-notification-tag';

  event.waitUntil( 
    self.registration.showNotification(title, { 
      body: body,
      icon: icon,
      tag: tag
    })
  );
});

@gibigate
Copy link
Author

gibigate commented Jan 8, 2019

У меня подключен fcm с дефолтными jsками, через пхп я отправляю такое:

$opts['postDataJson']['notification'] = array(
        'title' => $push['title'],
        'body' => $push['description'],
        'icon' => $config['firebase_files'].$push['icon'],
        'badge' => $config['firebase_files'].$push['badge'],
        'image' => $config['firebase_files'].$push['image'],
        'vibrate' => $push['vibrate'],
        'requireInteraction' => $push['interaction']>0 ? 'true' : 'false',
        'click_action' => 'URL/push.php?action=redirect&id='.$push['id'].'&subid='.$push['last_id'],
    );

Иконка показывается, а badge и image не работает, мне нужно отредактировать скрипт firebase-messaging-sw.js?

Содержимое:

// firebase-messaging-sw.js
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.6.8/firebase-messaging.js');

firebase.initializeApp({
    messagingSenderId: '1111111111111'
});

const messaging = firebase.messaging();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants