白脖什么意思| 吓着了有什么症状| 补骨脂是什么东西| 单核细胞百分比偏高是什么原因| 专情是什么意思| 2020年是什么生肖| 吃什么可以降血压| 坐东朝西是什么意思| 天珠有什么作用与功效| bone什么意思| 淋巴结什么原因引起的| sp是什么的缩写| 兔女郎是什么| 临床药学是干什么的| 肺部散在小结节是什么意思| 相拥是什么意思| 睡莲什么时候开花| 16 5是什么码| 腰间盘突出是什么症状| 郁金香长什么样子| 绝代双骄是什么意思| 方方土是什么字| 腊八粥是什么节日| 阿西吧是什么意思| 天年是什么意思| 喉咙发炎用什么药| 令郎是什么意思| 难入睡是什么原因| 洁身自爱是什么意思| 声带白斑是什么病严重吗| mid什么意思| 话梅泡水喝有什么好处和坏处| 菩提是什么| 耳洞发炎流脓用什么药| 活塞是什么意思| 十月二十是什么星座| 红花泡脚有什么好处| out什么意思| 乌江鱼是什么鱼| 口腔溃疡需要补充什么维生素| 五毒是什么| 什么是心肌缺血| 什么样的笑脸| 造孽是什么意思| 什么不可当| 体育生能报什么专业| 11月9号是什么星座| 尿结石是什么症状| 小腹疼痛挂什么科| 鹦鹉吃什么食物最好| 虹为什么是虫字旁| 疤痕增生是什么| 梦见黄鼠狼是什么意思| 内分泌失调什么症状| 安排是什么意思| 梦到猫是什么意思| 什么的天山| 正确的三观是什么| 新生儿眼屎多是什么原因| 胆小如鼠是什么生肖| 犬瘟吃什么药管用| 男性什么适合长期泡水喝| 豇豆是什么| 什么人适合吃人参| 水煮肉片放什么配菜| 遐想的意思是什么| 产褥期是什么意思| 胃为什么会疼| 淋巴细胞百分比高是什么原因| hyper是什么意思| 跖疣是什么东西| 睡眠障碍是什么原因引起的| 董监高是什么意思| 药店属于什么单位性质| 急性胃炎吃什么食物好| 黄瓜炒什么好吃| 92年是什么命| 老是口渴是什么原因| 三和大神什么意思| 人参泡酒有什么功效和作用| 六七是什么意思| 胆红素高说明什么| gucci是什么品牌| 吃了山竹不能吃什么| dmd是什么病| 什么水果补血效果最好| 为什么会得炎症| 吃什么排气| 苦瓜吃多了有什么坏处| 丝棉是什么材料| 鼻子冒热气是什么原因| 屈光不正是什么| 鱿鱼炒什么好吃| 晚的反义词是什么| 缺钙有什么症状| img什么意思| 胃火大吃什么药效果好| 高兴的反义词是什么| 弱智是什么意思| 凝血六项是检查什么的| 经常打嗝放屁是什么原因| 免疫力低有什么症状| 脾虚吃什么水果| 黄盖代表什么生肖| 下午一点是什么时辰| 嘴巴发甜是什么原因| 什么叫散光| 早期教育是什么| 喝醉是什么感觉| 戾是什么意思| 为什么啊| 四大皆空是什么生肖| 少女怀春是什么意思| 匆匆那年是什么意思| 孕妇补铁吃什么| 便秘应该挂什么科室| 法器是什么意思| 补血吃什么| 不明原因腹痛挂什么科| 赵雅芝是什么脸型| 胃疼和肚子疼有什么区别| 神经衰弱吃什么药效果最好| oof是什么意思| 龋坏是什么意思| 胡麻油是什么油| 肿瘤病人不能吃什么| 感冒口苦是什么原因| 牙医靠什么吃饭| 人体缺钾是什么症状| 草果长什么样| 吃什么维生素对眼睛好| 鳞状细胞是什么意思| 打呼噜挂什么科室| 婴儿喝什么奶粉| 无学历学什么技术好| 藕断丝连是什么意思| 什么情况下会得甲亢| pr是什么工作| 痛风可以吃什么肉类和蔬菜| ipi是什么意思| 蔓越莓有什么功效| 贞操带是什么| 足下生辉是什么意思| 拉肚子应该吃什么药| 什么是情感| 脸上长粉刺是什么原因引起的| 每天流鼻血是什么原因| 吃维生素a有什么好处| 伏特加是什么| 讨扰是什么意思| 腹胀是什么病的前兆| 什么的动作| 负心汉是什么意思| 头眩晕看什么科| 磨豆浆是什么意思| 什么的小草| 梦见拖地是什么意思| 为什么一洗澡月经就没了| ootd什么意思| 走路腰疼是什么原因| 胃打嗝是什么原因| 五行中水是什么颜色| 昊字五行属什么| 风湿因子高是什么原因引起的| 什么是伟哥| 什么是暗网| bioisland是什么牌子| 眼睛干痒用什么眼药水| 满族八大碗都有什么菜| remax是什么牌子| 肚子胀恶心想吐是什么原因| 嘴巴旁边长痘痘是为什么| 壁虎吃什么| 山东有什么特产| 肛周瘙痒是什么原因| 儿童超敏c反应蛋白高说明什么| 流产是什么样子的| 女性膀胱炎是什么症状| 什么叫基因检测| 早上起床眼睛浮肿是什么原因| 玉树临风是什么生肖| fila是什么品牌| 投诉医院打什么电话| 苯对人体有什么危害| 男人要的归属感是什么| 一件代发是什么意思| 吃什么对心脏最好| 火车头是什么意思| 空气刘海适合什么脸型| 504是什么错误| 吃什么醒酒| 鮰鱼是什么鱼| 腿肿脚肿是什么原因引起的| 梦见自己丢钱了什么征兆| 三宝是什么意思| 龟毛的性格指什么性格| 阳痿吃什么药| 女人戴什么招财又旺夫| 囊肿与肿瘤有什么区别| 血糖高吃什么降得快| 处女座和什么座最配| 鸡拉白色稀粪吃什么药| 一般事故隐患是指什么| 何去何从是什么意思| st-t改变是什么意思| 骨刺挂什么科| 42天产后检查挂什么科| 小孩手足口病吃什么食物好| 胃疼喝什么药| 梦见摘瓜是什么意思啊| 互粉是什么意思| 肝囊肿是什么原因引起的| 枪是什么生肖| 什么是云| 87年属什么| 蜂蜜有什么功效和作用| 慢慢张开你的眼睛是什么歌的歌词| 虾黄是虾的什么部位| 黄色衣服配什么颜色裤子好看| 垂的第三笔是什么| 梦见大火是什么意思| 小孩上火了吃什么降火最快| 女子与小人难养也什么意思| 叶子是什么意思| 什么是素数| 什么是直男| 人和是什么意思| 女生有喉结是什么原因| 光气是什么气体| 河南有什么市| 总是拉稀是什么原因| 家里出现蛇是什么征兆| 为什么人会打嗝| 一什么云彩| 什么帽不能戴| 大象喜欢吃什么食物| KP什么意思| 梦见磕头下跪什么意思| 吃什么补津液| 三焦指的是什么| 肝虚吃什么中成药| 经血粉红色是什么原因| 牛筋面是什么做的| 为什么放屁多| 肠炎发烧吃什么药| 验孕棒ct分别代表什么| 活血化瘀是什么意思| 什么叫打气 是吸毒吗| 一日三餐是什么意思| 眉毛里有痣代表什么| 桃花是指什么生肖| 属马的生什么属相的宝宝好| 嗯是什么意思| 待字闺中什么意思| force是什么牌子| 农历10月14日是什么星座| 手心朝上是什么意思| 社保卡是干什么用的| 为什么肝区隐隐作痛| 舟状腹见于什么疾病| 1977年出生属什么生肖| 维生素C起什么作用| 什么病会引起牙疼| 孕妇可以吃什么零食| 百度

“黑科技”加持 萤石新品发布会全程都是知识点

Along with the many other features for web apps on iOS and iPadOS 16.4, WebKit now includes support for the W3C’s Badging API.

A badged web application icon in the iOS dock showing the number 15.

This straightforward API allows web developers to badge the icon of a web app. This article explores the various features of the Badging API and how to use it, and our ongoing collaboration with W3C’s Web Applications Working Group to improve the specification.

Home Screen Web App Availability

In iOS and iPadOS 16.4, the Badging API is available exclusively for web apps the user has added to their home screen. You won’t find the API exposed to websites in Safari or other browsers, or in any app that uses WKWebView.

You can easily check for the availability of the API using feature detection for the setAppBadge function:

if ('setAppBadge' in navigator) {
  // API is available...
}  

Badges and Notifications

On iOS and iPadOS, badging has always been closely tied to notifications.

Apps built for macOS, iOS, and iPadOS are free to set their badge counts through platform specific APIs whenever they like. The user must grant the app permission to display notifications before the badge will appear.

Similarly, web apps are free to call setAppBadge() whenever they like, but the badge will only appear if the user has granted notifications permission.

To request notification permission, call Notification.requestPermission() as part of a user activation (such as a button click):

<button onclick="requestNotificationPermission()">
  Request notifications permission
</button>

<script>
  async function requestNotificationPermission() {
    const permission = await Notification.requestPermission();
    if (permission === 'granted') {
      // You can now use the Badging API
    }
  }
</script>

iOS and iPadOS will show this system prompt to the user for permission:

A browser permission prompt for asking the user to allow web notifications.

You can also check if a user has previously granted notifications permission by using the Permissions API:

async function checkNotificationPermission() {
  const permissionStatus = await navigator
    .permissions
    .query({ name: 'notifications' });

  switch (permissionStatus.state) {
    case 'granted':
      // You can use the Badging API
      break;
    case 'denied':
      // The user has denied the permission
      break;
    default:
      // The user has not yet granted or denied the permission
      await requestNotificationPermission();
      break;
  }
}
checkNotificationPermission();

Note that even though the user may have granted notifications permission, they remain in control of that permission through iOS or iPadOS Settings. As some users find badges distracting, they might leave the notifications permission enabled, but choose not to show the badge.

To retain user privacy, we never expose this user preference to the web app.

Setting and Clearing a Badge From a Web App

App badges represent the number of items requiring the user’s attention (e.g., “you have 5 unread messages“). What the number means is application dependent.

An application badge icon showing a badge with the number 5.

To update the application icon badge, pass a positive number to the navigator.setAppBadge() method:

async function setBadge(count) {
  if ('setAppBadge' in navigator) {
    try {
      await navigator.setAppBadge(count);
    } catch (error) {
      console.error('Failed to set app badge:', error);
    }
  }
}

// Set the badge count to 5
setBadge(5);

You can clear the badge by using navigator.clearAppBadge().

async function clearBadge() {
  if ('clearAppBadge' in navigator) {
    try {
      await navigator.clearAppBadge();
    } catch (error) {
      console.error('Failed to clear app badge:', error);
    }
  }
}

// Clear the badge
clearBadge();

Alternatively, calling navigator.setAppBadge(0) is equivalent to calling navigator.clearAppBadge().

Using the API From a Service Worker

In addition to being exposed to window objects, the Badging API is exposed in Web Worker contexts.

This makes it particularly useful for apps that support Web Push as it is trivial to update your application badge while your Service Worker handles a push event.

// Function to determine the badge count based on the event data
function determineBadgeCount(data) {
  // Process the data to compute the badge count
}

self.addEventListener('push', (event) => {
  let promises = [];

  if ('setAppBadge' in self.navigator) {
    const badgeCount = determineBadgeCount(event.data);
    // Promise to set the badge
    const promise = self.navigator.setAppBadge(badgeCount);
    promises.push(promise);
  }

  // Promise to show a notification
  promises.push(self.registration.showNotification("You've got mail!"));

  // Finally...
  event.waitUntil(Promise.all(promises));
});

When requesting a push subscription you must promise that all pushes will be user visible events. This means that each push event you process must result in a user visible notification being displayed with a call to self.registration.showNotification()

You are encouraged to update your application badge when handling a push event, but a badge update by itself does not fulfill the “user visible” requirement; Keep showing those notifications!

Security Restrictions for Third-Party

When the user added your web app to their Home Screen, they were indicating their trust in you as a first party.

JavaScript that calls navigator.setAppBadge() in an attempt to update the badge count must come from a frame that is the same-origin as your top-level document. Calls to navigator.setAppBadge() from cross-origin frames have no effect.

Evolving the Badging API at the W3C

We’re collaborating with the W3C Web Applications Working Group and its members, particularly with Microsoft who have partnered with us as co-editors of the Badging API specification. This collaboration allows us to create a more consistent, secure, and privacy-preserving API across browsers and operating systems. The Badging API specification was previously edited by folks from Google. We’re excited to work with the W3C membership to continue its evolution.

抑扬顿挫什么意思 网线长什么样 无冕之王是什么意思 突然消瘦是什么原因 后背的骨头叫什么
吃避孕药对身体有什么影响 南昌有什么特产 术后可以吃什么水果 什么茶叶好喝 梦见河水是什么意思
喉咙有痰挂什么科 盲目是什么意思 杆菌是什么意思 什么纸贵 有毒是什么意思
拉比是什么意思 61是什么意思 癸丑五行属什么 什么奶粉好 张学友属什么生肖
牛肉馅配什么菜包饺子好吃hcv8jop9ns1r.cn 做护士需要什么条件naasee.com 自律是什么意思hcv9jop3ns7r.cn 侍中是什么官beikeqingting.com 梅核气西医叫什么hcv8jop9ns4r.cn
反物质是什么hcv8jop5ns2r.cn 夸父为什么要追赶太阳hcv7jop7ns2r.cn 刺史相当于现在什么官hcv8jop5ns0r.cn 继女是什么意思hcv7jop6ns2r.cn 柔软的什么hcv9jop8ns3r.cn
女性绝经期在什么年龄是正常的hcv8jop6ns0r.cn 28年是什么婚hcv8jop3ns9r.cn 梦见空棺材是什么意思imcecn.com 几何图形是什么hcv8jop5ns4r.cn 沙棘是什么hcv9jop7ns3r.cn
摩羯座和什么座最配对hcv8jop0ns4r.cn 五行木生什么hcv9jop7ns4r.cn 九加虎念什么hcv7jop9ns3r.cn 7.6什么星座hcv8jop4ns6r.cn 受精卵着床有什么感觉hcv8jop0ns2r.cn
百度