當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript service-worker.SwPush類代碼示例

本文整理匯總了TypeScript中@angular/service-worker.SwPush的典型用法代碼示例。如果您正苦於以下問題:TypeScript SwPush類的具體用法?TypeScript SwPush怎麽用?TypeScript SwPush使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了SwPush類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: constructor

    constructor(updates: SwUpdate, push: SwPush, private http: HttpClient) {
        interval(10000).subscribe(() => updates.checkForUpdate());

        updates.available.subscribe(event => {
            if (prompt('Update available for this app. Do you want to update it?')) {
                updates.activateUpdate().then(() => document.location.reload());
            }
        });
        updates.activated.subscribe(event => {
            console.log('old version was', event.previous);
            console.log('new version is', event.current);
        });
        console.log('Push code');
        push.requestSubscription({serverPublicKey: 'BDTrenhMvFL5hexEce8suYQkMeXajUwKG0NdZboLhFBM3tgJ6ENXCxv3CZxiGPDoc_1v6848KMJiaMwSkLUea8g'}).then(
            (success) => {
                console.log(success);
                this.http.post('http://localhost:9020/save-subscription', success).subscribe(()=> {
                    push.messages.subscribe(message => console.log(message));
                });
            },
            (error) => console.error(error)
        )
    }
開發者ID:alcfeoh,項目名稱:ng2-weather,代碼行數:23,代碼來源:app.component.ts

示例2: subscribe

 subscribe() {
   console.log('Subscribed users');
   this.swPush.requestSubscription({
     serverPublicKey: 'BNMN_-1BUbcWu_HDPo-fedCKVZRtbx_Lv1718BzoFfiERREFBeknxGLmJvn5dzU1xM5zS-v5nkE8gU1ak49YOcE'
   })
     .then(sub => {
       this.subscribeModel = new Notification();
       this.subscribeModel.userSubscriptions = sub;
       this.settingService.addPushSubscriber(this.subscribeModel).subscribe();
     })
     .catch(err => console.error('Could not subscribe to notifications', err));
 }
開發者ID:RIntegerB2B,項目名稱:SaifSeller,代碼行數:12,代碼來源:subsrcibe.component.ts

示例3: register

  register(): Promise<void | Subscription> {

    // SUBSCRIBE for notifications
    this.swPush.messages.subscribe(message => {
      console.log('received message' + JSON.stringify(message));
    });

    // REGISTER BACKEND
    return this.swPush.requestSubscription({
      serverPublicKey: environment.appConfig.vapidPublicKey
    }).then((subscription: PushSubscription) => {
      console.log('register for push at ' + this.endpoint);
      return this.http.post(this.endpoint, new PushRegistration(subscription)).subscribe(() =>
        console.log('registered for push'));
    });
  }
開發者ID:fischermatte,項目名稱:geolud,代碼行數:16,代碼來源:push.service.ts

示例4: unregister

 unregister(): Promise<void> {
   return this.swPush.unsubscribe().then(() => {
     console.log('unregistered from push');
   });
 }
開發者ID:fischermatte,項目名稱:geolud,代碼行數:5,代碼來源:push.service.ts


注:本文中的@angular/service-worker.SwPush類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。