|
5 | 5 | - CD to the root folder of the project and run `yarn` to install all Node packages. |
6 | 6 | - Then run `yarn start` to start the project and automatically launch a browser. |
7 | 7 | - Click `Subscribe Web Push` and copy a subscription JSON object in a text box. |
8 | | -- Use subscription object on a server side to send push notification. |
| 8 | +- Use copied subscription object on a server side to send push notification. |
9 | 9 | - This project requires Node.js version >= 14. |
10 | 10 |
|
11 | | - |
12 | | -# Send push notification from a server |
13 | | -- Set a push subscription object that we get after a user's subscribed web push in `PushMessageFromServer.js` |
| 11 | +# How to send a push message from a server |
| 12 | +- Set a `pushSubscription` object in `PushMessageFromServer.js`, we can get it after subscribing. |
14 | 13 | - Then execute the following command: |
15 | | - ```sh |
16 | | - $ node PushMessageFromServer.js |
17 | | - ``` |
| 14 | +```sh |
| 15 | +$ node PushMessageFromServer.js |
| 16 | +``` |
18 | 17 |
|
19 | 18 | # Trouble shooting |
20 | | -## Notification does not always show as banner on Windows. |
| 19 | + |
| 20 | +## Notification does not always show as a banner on Windows. |
21 | 21 | - Try to turn off focus assist. |
| 22 | + |
22 | 23 | ## No push notification message at all |
23 | | -- You may need to manually update service worker. Open Chrome developer tool with ctrl+shift+i keys and then go to application tab. |
24 | | - Then click Service Workers node > Skip waiting service worker. |
| 24 | +- You may need to manually update service worker. Open a Chrome developer tool with `ctrl+shift+i` keys |
| 25 | + and select an application tab. |
| 26 | +- Then click Service Workers node > Skip waiting service worker. |
25 | 27 |
|
26 | 28 | # Key concept |
27 | 29 | - Generate publish and private key public and private keys with the following code |
|
30 | 32 | const vapidKeys = webPush.generateVAPIDKeys(); |
31 | 33 | console.log(vapidKeys); |
32 | 34 | ``` |
33 | | -- Use a public key in subscription script (App.tsx) |
34 | | -- User subscribes web push with subscription script. |
35 | | -- Use both public, private keys and subscription object on server script (PushMessageFromServer.js) to send push to a user. |
| 35 | +- Use a public key in subscription script (PushSubscription.tsx) |
| 36 | +- A user subscribes web push with subscription script (PushSubscription.tsx) and bet subscription object. |
| 37 | +- Use public, private keys and subscription object on server script (PushMessageFromServer.js) to send push message to a subscribed user. |
36 | 38 | - Subscription object is what we store in a database. It is an identity of a subscribed user. |
37 | | -- Use service worker script (service-worker.js) to handle push notification and customize how to show it to a user |
| 39 | +- Use a service worker script (service-worker.js) to handle push notification and customize how to show it to a user. |
38 | 40 | - You can test push with a localhost and do need to deploy to public URL |
39 | 41 |
|
40 | | -# Get subscription object on a published website |
41 | | -- For the main project in .NET Thailand repository, it can be accessed as http://www.dotnetthailand.com/web-push-api-example/. |
| 42 | +# Get subscription object on a published website for testing only |
| 43 | +- It can be accessed as http://www.dotnetthailand.com/web-push-api-example/. |
42 | 44 |
|
43 | | -# Useful articles for .NET Web Push |
| 45 | +# For using Web Push in .NET project. Here are some useful articles: |
44 | 46 | - https://www.pluralsight.com/guides/html5-desktop-notifications-with-react |
45 | 47 | - https://blog.elmah.io/how-to-send-push-notifications-to-a-browser-in-asp-net-core/ |
46 | 48 | - https://www.bartvanuden.com/2018/01/23/push-notifications-to-your-pwa-with-asp-net-core-2-0-and-aurelia/ |
47 | 49 | - https://www.tpeczek.com/2017/12/push-notifications-and-aspnet-core-part.html |
48 | 50 | - https://stackoverflow.com/a/47617427/1872200 |
| 51 | +- https://knowledgebase.webengage.com/docs/web-push-image-text-specifications |
| 52 | +- https://web-push-book.gauntface.com/demos/notification-examples/ |
| 53 | + |
| 54 | +# Requirements for Web Push on iOS |
| 55 | +- iOS 16.4+ (Released March 2023) |
| 56 | +- Safari or any iOS browser using WebKit (all iOS browsers use WebKit, including Chrome, Firefox, Edge) |
| 57 | +- Your site must be: |
| 58 | + - Served over HTTPS |
| 59 | + - Installed as a PWA (Progressive Web App) via "Add to Home Screen" |
| 60 | + - Must use the standard Push API + Notification API |
49 | 61 |
|
50 | | -# Upgrade React to major release version |
51 | | - ```sh |
| 62 | +# How Upgrade React to the major release version |
| 63 | +```sh |
52 | 64 | yarn upgrade react --latest |
53 | 65 | yarn upgrade react-dom --latest |
54 | 66 | yarn upgrade react-dom --latest |
55 | 67 | yarn upgrade @types/react --latest |
56 | 68 | yarn upgrade @types/react-dom --latest |
57 | | - ``` |
| 69 | +``` |
| 70 | + |
0 commit comments