在离子4项目中使用OneSignal Api

问题描述 投票:0回答:1

我正在尝试使用ionic 4使用来自one signal的帖子请求创建推送通知

这是我发送POST请求的方式:

    async presentAlertMultipleButtons() {
        const alert = await this.alertController.create({
            header: 'Confirm',
            subHeader: 'Your dress is added',
            message: 'Admin team will review the dress and post it as soon as possible.',
            buttons: ['Ok'],
            mode: 'ios'
        });

        await alert.present();
        const post_data = {
            'app_id': 'xxxxxxxxxxxxxxxxxxxxxx',
            'contents': {
                'en': 'new dress added to fostania'
            },
            'headings': {
                'en': 'new dress'
            },
            'included_segments': ['admins'],
        }
        const httpOptions2 = {
            headers: new HttpHeaders({
                'Content-Type': 'application/json',
                'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxx'
            })
        };
        this.httpClient.post('https://onesignal.com/api/v1/notifications', post_data, httpOptions2);

        this.router.navigate(['/list']);
    }

我在为用户显示操作完成的通知(警报)后添加了帖子。

它没有发送,即使没有任何回复!

angular api ionic-framework ionic4 onesignal
1个回答
0
投票

感谢@ R.Richards评论。

我改变了this.httpClient.post('https://onesignal.com/api/v1/notifications', post_data, httpOptions2);

this.httpClient.post('https://onesignal.com/api/v1/notifications', post_data, httpOptions2)
                        .subscribe(new_data => {
                            console.log(new_data)
                        }, error => {
                            console.log(error);
                        });

它现在有效

© www.soinside.com 2019 - 2024. All rights reserved.