你好,我正在使用Angular Service worker在我的Web上发送通知,但是当我尝试使用Web Push comand在浏览器中发送通知时,出现了json错误 ngsw-worker.js:2023未捕获的SyntaxError:JSON中位置1处的意外令牌m 在Driver.onPush(ngsw-worker.js:2023) 在ngsw-worker.js:1913
网络的推送发送通知--endpoint = “https://fcm.googleapis.com/fcm/send/e8p-BuHFC6E:APA91bHdSY408RYfoNYfPepyPQRgmEDuCTzHOPVQ44tg33vTuYOQafCejxG28SOpkZJn6kMMyUVCAB_imJAc_35Yy4WQuoyDYAeUPOcrzzlWfXe0Ws0TQ_z_ynvKL_bGfnobZTT7EtWB” --key = “XXXXXXXXX” --auth = “XXXXXXXX” - payload ='{data:“ asdasda”}'--vapid-subject =“ mailto:e@yoin.org” --vapid-pubkey = --vapid-pvtkey =
如果有效载荷格式是其他格式,我不知道我在做什么
答案 0 :(得分:0)
@Matias 这是由于nsgsw-worker.js无法与ngsw.json正确通信。请再次检查您的ngsw.json。如果不行,请发送您的ngsw.json。您可以从https://blog.angular-university.io/angular-service-worker/寻求帮助,或者应该是
{
"index": "/index.html",
"assetGroups": [{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js"
]
}
}, {
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**"
]
}
}, {
"buildOptimizer": true,
"serviceWorker": true,
"ngswConfigPath": "src/ngsw-config.json",
"fileReplacements": [{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}]
}
]
}
答案 1 :(得分:0)
@Anil 感谢您的回答,我使用该教程来指导我这是我的ngsw-config.json
import React, { Component } from 'react'
import {
AppRegistry,
StyleSheet,
Text,
View,
} from 'react-native'
export default class App extends Component {
render() {
return (
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.cross}>X</Text>
<Text style={styles.headerText}>Invester Profile</Text>
</View>
</View>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
header: {
backgroundColor:'#212121',
height: 159.9,
flexDirection: 'row',
},
headerText: {
color: 'white',
marginTop: 20,
textAlign: 'center',
},
cross: {
color: 'white',
marginTop: 20,
}
})
如果发送空消息,它将返回另一个错误,我不知道有效载荷的构造是否正确
{
"$schema": "./node_modules/@angular/service-worker/config/schema.json",
"index": "/index.html",
"assetGroups": [
{
"name": "app",
"installMode": "prefetch",
"resources": {
"files": [
"/favicon.ico",
"/index.html",
"/*.css",
"/*.js",
"/assets/*"
]
}
},
{
"name": "assets",
"installMode": "lazy",
"updateMode": "prefetch",
"resources": {
"files": [
"/assets/**",
"/*.(eot|svg|cur|jpg|png|webp|gif|otf|ttf|woff|woff2|ani)"
]
}
}
],
"dataGroups": [
{
"name": "api-freshness",
"urls": [
"/Notification"
],
"cacheConfig": {
"maxSize": 100,
"maxAge": "3d",
"timeout": "1m",
"strategy": "freshness"
}
}
]
}