本文整理汇总了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;未经允许,请勿转载。 |
请发表评论