Created
November 4, 2017 13:04
-
-
Save webmaxru/63f27022e45b8a85297c592e64faac7f to your computer and use it in GitHub Desktop.
Unsubscription using SwPush
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| unsubscribeFromPush() { | |
| // Get active subscription | |
| this.swPush.subscription | |
| .take(1) | |
| .subscribe(pushSubscription => { | |
| console.log('[App] pushSubscription', pushSubscription) | |
| // Delete the subscription from the backend | |
| this.pushService.deleteSubscriber(pushSubscription) | |
| .subscribe( | |
| res => { | |
| console.log('[App] Delete subscriber request answer', res) | |
| let snackBarRef = this.snackBar.open('Now you are unsubscribed', null, { | |
| duration: this.snackBarDuration | |
| }); | |
| // Unsubscribe current client (browser) | |
| pushSubscription.unsubscribe() | |
| .then(success => { | |
| console.log('[App] Unsubscription successful', success) | |
| }) | |
| .catch(err => { | |
| console.log('[App] Unsubscription failed', err) | |
| }) | |
| }, | |
| err => { | |
| console.log('[App] Delete subscription request failed', err) | |
| } | |
| ) | |
| }) | |
| } |
@bolajipemipo i think this is because you are using rxjs 5.5+ and the syntax changed.
use new lettable/pipable import statements in the file header:
import { map, catchError, take .. } from 'rxjs/operators';
and you should use take in a pipe:
this.swPush.subscription
.pipe(take(1))
.subscribe(pushSubscription => {
console.log('[App] pushSubscription', pushSubscription)
// Delete the subscription from the backendIf you want to use more operators use them like below:
this.swPush.subscription
.pipe(
take(1),
map(val => val),
filter(val => val)
)
.subscribe(pushSubscription => {
console.log('[App] pushSubscription', pushSubscription)@petivagyok16 Can you please explain why you need to pipe the subscription?
I try to unsubscribe and can get it to work with or without pipe. pushSubscription is always null in my case although I'm sure that I'm subscribed (because I get notifications). Why? How to make it work? Unfortunately, there is no document.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @webmaxru,
Got this error
Property 'take' does not exist on type 'Observable<PushSubscription>'.Thanks.