From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/api/pushmanager/getsubscription/index.html | 149 +++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 files/ja/web/api/pushmanager/getsubscription/index.html (limited to 'files/ja/web/api/pushmanager/getsubscription') diff --git a/files/ja/web/api/pushmanager/getsubscription/index.html b/files/ja/web/api/pushmanager/getsubscription/index.html new file mode 100644 index 0000000000..d2fabe1b86 --- /dev/null +++ b/files/ja/web/api/pushmanager/getsubscription/index.html @@ -0,0 +1,149 @@ +--- +title: PushManager.getSubscription() +slug: Web/API/PushManager/getSubscription +tags: + - API + - Experimental + - Method + - PushManager + - Reference + - Service Workers +translation_of: Web/API/PushManager/getSubscription +--- +

{{SeeCompatTable}}{{ApiRef("Push API")}}

+ +

{{domxref("PushManager")}} インターフェースの PushManager.getSubscription() メソッドは、既存のプッシュサブスクリプションを取得します。

+ +

これは既存のプッシュサブスクリプションの詳細を含む {{domxref("PushSubscription")}} を解決する {{jsxref("Promise")}} を返します。既存のプッシュサブスクリプションが存在しない場合 null 値で解決されます。

+ +

構文

+ +
​PushManager.getSubscription().then(function(pushSubscription) { ... } );
+ +

パラメーター

+ +

なし。

+ +

戻り値

+ +

{{domxref("PushSubscription")}} オブジェクトで解決される {{jsxref("Promise")}}。

+ +

+ +

このコードスニペットは、push messaging and notification sample から取ってきました(使用できるライブデモはありません)。

+ +
// サブスクリプションをチェックするために、service worker の登録が必要である。
+  navigator.serviceWorker.ready.then(function(serviceWorkerRegistration) {
+    // 既にプッシュメッセージサブスクリプションがあるか?
+    serviceWorkerRegistration.pushManager.getSubscription()
+      .then(function(subscription) {
+        // プッシュメッセージからサブスクライブ / アンサブスクライブ
+        // する任意の UI を有効にする
+        var pushButton = document.querySelector('.js-push-button');
+        pushButton.disabled = false;
+
+        if (!subscription) {
+          // プッシュを購読していない場合、ユーザーがプッシュできるように
+          // UI を設定する。
+          return;
+        }
+
+        // 最新の subscriptionId でサーバ同期を維持する。
+        sendSubscriptionToServer(subscription);
+
+        showCurlCommand(subscription);
+
+        // プッシュメッセージの購読を表示するために
+        // UI を設定する。
+        pushButton.textContent = 'Disable Push Messages';
+        isPushEnabled = true;
+      })
+      .catch(function(err) {
+        window.Demo.debug.log('Error during getSubscription()', err);
+      });
+  });
+}
+ +

仕様

+ + + + + + + + + + + + + + +
仕様状態コメント
{{SpecName('Push API', '#widl-PushManager-getSubscription-Promise-PushSubscription', 'getSubscription()')}}{{Spec2('Push API')}}初期定義。
+ +

ブラウザ実装状況

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
機能ChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
基本サポート{{CompatChrome(42.0)}}{{CompatGeckoDesktop(44.0)}}[1]{{CompatNo}}{{CompatUnknown}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
機能AndroidAndroid WebviewFirefox Mobile (Gecko)Firefox OSIE MobileOpera MobileSafari MobileChrome for Android
基本サポート{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile(48)}}[2]{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatNo}}{{CompatChrome(42.0)}}
+
+ + + +

関連項目

+ + -- cgit v1.2.3-54-g00ecf