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

Feat#9 hyein/notification #16

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Feat#9 hyein/notification #16

wants to merge 4 commits into from

Conversation

hae2ni
Copy link

@hae2ni hae2ni commented Jul 7, 2023

๐Ÿ”ฅ Related Issues

๐Ÿ’™ ์ž‘์—… ๋‚ด์šฉ

  • [ ] ~ PWA PUSH ์•Œ๋ฆผ

โœ… PR Point

  • service worker ๊ตฌํ˜„์ด ํ•ต์‹ฌ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • ์—ฌ๊ธฐ์„œ๋„ config ๋ฐ›์•„์™”์–ด์—ฌ

// importScripts("https://www.gstatic.com/firebasejs/9.5.0/firebase-app.js");
// importScripts("https://www.gstatic.com/firebasejs/9.5.0/firebase-messaging.js");
importScripts("https://www.gstatic.com/firebasejs/9.0.0/firebase-app-compat.js");
importScripts("https://www.gstatic.com/firebasejs/9.0.0/firebase-messaging-compat.js");
const firebaseConfig = {
  apiKey: import.meta.env.REACT_APP_API_KEY,
  authDomain: "pre-gwasuoneshot.firebaseapp.com",
  projectId: "pre-gwasuoneshot",
  storageBucket: "pre-gwasuoneshot.appspot.com",
  messagingSenderId: import.meta.env.REACT_APP_MESSAGING_ID,
  appId: import.meta.env.REACT_APP_APP_ID,
  measurementId: import.meta.env.REACT_APP_MEASUREMENT_ID,
};

firebase.initializeApp(firebaseConfig);

const messaging = firebase.messaging();

messaging.onBackgroundMessage(messaging, (payload) => {
  console.log("[firebase-messaging-sw.js] Received background message ", payload);

  // Customize notification here
  const notificationTitle = "Tutice";
  const notificationOptions = {
    body: payload,
    icon: "/fruit.png",
  };

  self.registration.showNotification(notificationTitle, notificationOptions);
});

  • firebase-messaging-sw.js ํŒŒ์ผ์˜ ์ด๋ฆ„๊ณผ ํŒŒ์ผ์˜ ์œ„์น˜๊ฐ€ ์กฐ๊ธˆ์ด๋ผ๋„ ํ‹€๋ฆฌ๋ฉด ์•„์˜ˆ ๋จน์ง€ ์•Š๋”๋ผ๊ตฌ์š”! ์ด๊ฑฐ ์ฃผ์˜ํ•˜์—ฌ์•ผ ํ•  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
  • service worker๋Š” public ํด๋” ๋ฐ‘์—,
  • ๋Œ์•„๊ฐ€๋Š”(?) token์„ ๋ฐ›์•„์˜ค๋Š” ํŒŒ์ผ์€ App.tsx ๋ฐ‘์— ๋‘์—ˆ๊ณ , App.tsx์—์„œ token์„ ๋ฐ›์•„์˜ค๋Š” ๋ถ€๋ถ„์„ importํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.
  • ์ดํ›„, token์„ ๋ฐ›์•„์˜ค๋ฉด,

image
์ด๋Ÿฐ์‹์œผ๋กœ ๋œจ๊ฒŒ ๋˜๋Š”๋ฐ,
์ด ๋ถ€๋ถ„๊ณผ ํ•จ๊ป˜ firebase console์—์„œ
image
ํ…Œ์ŠคํŠธ ๋ถ€๋ถ„์— ๋‚ด์šฉ๊ณผ ์ œ๋ชฉ์„ ์ž…๋ ฅํ•˜๊ณ  token์„ ๋„ฃ์–ด์ฃผ๊ณ  ๋ณด๋‚ด๋ฉด data๊ฐ€ ์ž˜ ๋ฐ›์•„์™€์ง‘๋‹ˆ๋‹ค!

์ด๋ ‡๊ฒŒ push ์•Œ๋ฆผ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์œผ๋ฉด,
๋งˆ์ง€๋ง‰์œผ๋กœ notification์˜ title๊ณผ body๋ถ€๋ถ„์„ ๋ณด์—ฌ์ฃผ๋ฉด ๋  ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค....

์•„์˜ˆ ์•Œ๋žŒ ๋ฉ”์„ธ์ง€๋ž‘ ์•„์ด์ฝ˜๊นŒ์ง€ ๋„์šธ ์ˆ˜ ์žˆ๊ฒŒ ์ข€๋” ๋ฆฌํŒฉํ† ๋งํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค!!!

๊ฒฐ๊ณผ ํ™”๋ฉด=> ๊ทผ๋ฐ chrome์—์„œ๋งŒ ํ•ด๋ด์„œ(์•„์ดํฐ์ด์Šˆ) pwa ์ž์ฒด๋กœ ๋ฐ”๊พธ์ง€๋„ ์•Š์€ ๊ฒƒ ๊ฐ™์•„์„œ,,, ์ž์‹ ๊ฐ์€ ์ œ๋กœ์ž„
image

๐Ÿ˜ก Trouble Shooting

  • yarn add firebase๋ฅผ ํ•ด๋„ firebase๋ฅผ ์ธ์ง€ํ•˜์ง€ ๋ชปํ•˜๋Š” ์ƒํ™ฉ์ด ์žˆ์—ˆ๊ณ ,
  • import @firebase/messaging์„ ํ•ด๋„ ์ธ์ง€ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹คใ… ใ… 
  • ๊ฒฐ๊ตญ์—๋Š” ์š”๊ฑฐ ๋ ˆํฌ์ง€ํ† ๋ฆฌ๋ฅผ ์ œ ๊ฑธ๋ฃจ fetchํ•ด์„œ ์ง„ํ–‰ํ–ˆ๊ณ  ๊ฑฐ๊ธฐ์„œ๋Š” ๋‹ค ์ž˜ ๋Œ์•„๊ฐ”์Šต๋‹ˆ๋‹ค..!

๐Ÿ‘€ ์Šคํฌ๋ฆฐ์ƒท / GIF / ๋งํฌ

image

๐Ÿ“š Reference

PWA PUSH ๊ตฌํ˜„์— ๋Œ€ํ•˜์—ฌ
PWA PUSH ์˜ˆ์‹œ์ฝ”๋“œ

์‚ฌ์‹ค ์ฝ”๋“œ๋Š” ์ œ ๋ ˆํฌ์ง€ํ† ๋ฆฌ,,,์—์„œ ๋ณด์‹œ๋Š” ๊ฒŒ ๋‚˜์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค! (๋ณต๋ถ™ํ•œ๋‹ค๊ณ  ๋ถ™์˜€๋Š”๋ฐ ์‚ฌ๋žŒ์ธ์ง€๋ผ ๋นผ๋จน์—ˆ์„ ๊ฒƒ ๊ฐ™๊ธฐ๋„ ํ•˜๊ณ  ๋ฆฌํŒฉํ† ๋ง๋„ ๊ทธ์ชฝ์—์„œ ์ง„ํ–‰ํ•˜๋ ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค)

@hae2ni hae2ni added feat-function ๊ธฐ๋Šฅ๊ตฌํ˜„ํ–ˆ์–ด์š” ํ˜œ์ธ ํ˜œ์ธ ๋‹ด๋‹น labels Jul 7, 2023
@hae2ni hae2ni self-assigned this Jul 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat-function ๊ธฐ๋Šฅ๊ตฌํ˜„ํ–ˆ์–ด์š” ํ˜œ์ธ ํ˜œ์ธ ๋‹ด๋‹น
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ Hyein ] ์•Œ๋ฆผ ๊ตฌํ˜„
1 participant