iT邦幫忙

1

蘋果手機 Safari 瀏覽器 Firebase 推播服務紀錄

  • 分享至 

  • xImage

最近想弄手機板的推播,安卓可以~但蘋果不行...
這幾天找資料..查不到教學..
今天靠自己的推測終於確認流程跟方法..哀
還好Apple在今年iOS、iPadOS 更新IOS版本到 16.4
讓蘋果手機可以發推播通知了
之前產生網頁QR碼跟手機掃描QR碼程式碼的文章教學很快~
這次沒文章教學~果然很花時間XD..

只要更新IOS版本到 16.4
在【設定】→【safari】→【進階】→【Experimental Features】
開啟 【Notifications API】 就可以了(預設是關閉)

如底下流程圖:
1.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369yJSHmkHiKe.png
2.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369SpXk7o2WuK.png
3.
https://ithelp.ithome.com.tw/upload/images/20230705/200613699VBJ32uzn2.png
4.
https://ithelp.ithome.com.tw/upload/images/20230705/200613694FPRaDeSct.png
5.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369IPDt4rZX1I.png
6.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369ertn7KZ3a5.png
7.
https://ithelp.ithome.com.tw/upload/images/20230705/200613693BGYlma5n9.png
8.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369isEYXQuxzQ.png
9.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369gP9Ibb3ELR.png
10.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369ddCjcRGidk.png
11.
https://ithelp.ithome.com.tw/upload/images/20230705/200613699HME3ILU0y.png
12.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369oHJnVEWxFT.png
13.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369e0qxKr3RrW.png
14.
https://ithelp.ithome.com.tw/upload/images/20230705/20061369mhoi89E7dL.png

網頁測試程式碼:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>webfcm</title>
<link rel="manifest" href="manifest.json" />
</head>
<body>
測試FCM...
<input type="button" value="測試" onclick="requestPermission();" />
<br />
<div id="NotMsg"></div>
<div id="TxtMsg"></div>

<script type="text/javascript">
    if (!('Notification' in window)) {
        var NotMsg = document.getElementById("NotMsg");
        NotMsg.innerHTML = '此瀏覽器無法使用通知!'
    }else{
        var NotMsg = document.getElementById("NotMsg");
        NotMsg.innerHTML = '瀏覽器接受通知設定!'
    }

    //確認權限
    function requestPermission() {
        var TxtMsg = document.getElementById("TxtMsg");
        TxtMsg.innerHTML = '正在確認瀏覽器通知權限:'
        Notification.requestPermission().then((permission) => {
            if (permission === 'granted') {
                TxtMsg.innerHTML += '[瀏覽器已允許通知]';
            } else {
                TxtMsg.innerHTML += '[瀏覽器不接受通知]';
            }
        });
    }

</script>
</body>
</html>

manifest.json 檔案

{
  "short_name": "Notificare",
  "name": "Notificare",
  "start_url": "/",
  "background_color": "#ffff00",
  "description": "",
  "display": "standalone",
  "orientation": "portrait-primary",
  "icons": [
    {
      "src": "",
      "sizes": "36x36",
      "type": "image/png",
      "density": "0.75"
    }
  ]
}
Annie iT邦新手 2 級 ‧ 2023-07-07 10:01:18 檢舉
謝謝分享經驗,剛好前陣子有想了解這塊~~~
我也算好運~剛好今年蘋果手機改版到可以發訊息通知~
要不然去年~好像有人嘗試做~但是還不支援發訊息通知~
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答