-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/pwa' into develop
- Loading branch information
Showing
9 changed files
with
4,593 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "My PWA", | ||
"short_name": "PWA", | ||
"start_url": "/", | ||
"display": "standalone", | ||
"background_color": "#ffffff", | ||
"description": "My awesome Progressive Web App!", | ||
"icons": [ | ||
{ | ||
"src": "/termsCheck.png", | ||
"sizes": "192x192", | ||
"type": "image/png" | ||
}, | ||
{ | ||
"src": "/termsCheck.png", | ||
"sizes": "512x512", | ||
"type": "image/png" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// sw.js | ||
|
||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable no-unused-vars */ | ||
|
||
// install event | ||
self.addEventListener('install', (e) => { | ||
// console.log('[Service Worker] installed'); | ||
}); | ||
|
||
// activate event | ||
self.addEventListener('activate', (e) => { | ||
// console.log('[Service Worker] actived', e); | ||
}); | ||
|
||
// fetch event | ||
self.addEventListener('fetch', (e) => { | ||
// console.log('[Service Worker] fetched resource ' + e.request.url); | ||
}); | ||
|
||
// 등등 앱에 따라 pwa 기능을 추가하고 sw.js에 작성할 수 있습니다. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
export const registerServiceWorker = () => { | ||
if ('serviceWorker' in navigator) { | ||
window.addEventListener('load', () => { | ||
navigator.serviceWorker | ||
.register('/sw.js') | ||
.then((registration) => { | ||
console.log('Service Worker 등록 성공:', registration); | ||
}) | ||
.catch((error) => { | ||
console.log('Service Worker 등록 실패:', error); | ||
}); | ||
}); | ||
} | ||
}; | ||
|
||
export const requestNotificationPermission = () => { | ||
if ('Notification' in window) { | ||
Notification.requestPermission().then((permission) => { | ||
if (permission === 'granted') { | ||
console.log('푸시 알림 권한이 허용됨'); | ||
} else { | ||
console.log('푸시 알림 권한이 거부됨'); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
export const sendPushNotification = (title: string, body: string) => { | ||
if ('serviceWorker' in navigator && 'PushManager' in window) { | ||
navigator.serviceWorker.ready.then((registration) => { | ||
registration.showNotification(title, { | ||
body, | ||
icon: '/termsCheck.png' | ||
}); | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useEffect } from 'react'; | ||
import { | ||
registerServiceWorker, | ||
requestNotificationPermission, | ||
sendPushNotification | ||
} from './SetUp'; | ||
|
||
export const Test = () => { | ||
// 푸시 알림 테스트 | ||
const clickPushHandler = () => { | ||
sendPushNotification('매직포스 알림', '알림 가나요?'); | ||
}; | ||
useEffect(() => { | ||
registerServiceWorker(); | ||
requestNotificationPermission(); | ||
// 직접 푸시 알림 테스트 | ||
sendPushNotification('테스트 알림', '테스트 알림입니다.'); | ||
}, []); | ||
|
||
return <button onClick={clickPushHandler}>알림 보내기</button>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters