本文整理汇总了TypeScript中@angular/service-worker.SwPush.requestSubscription方法的典型用法代码示例。如果您正苦于以下问题:TypeScript SwPush.requestSubscription方法的具体用法?TypeScript SwPush.requestSubscription怎么用?TypeScript SwPush.requestSubscription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/service-worker.SwPush
的用法示例。
在下文中一共展示了SwPush.requestSubscription方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: 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));
}
示例2: 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'));
});
}
示例3: 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)
)
}