[英]Cordova Firebase Plugin - Not showing notifications in notification bar on iOS
I'm using this plugin with cordova: cordova-plugin-firebase 0.1.18 "Google Firebase Plugin" its working fine on android,also on ios i got token using method 我将此插件与cordova配合使用:cordova-plugin-firebase 0.1.18“ Google Firebase插件”在android上也能正常工作,在ios上我也使用了方法
window.FirebasePlugin.getToken
but notification not coming in notification bar weather its in foreground or background call back of notification never come in using method 但是通知没有进入通知栏,它的前台或后台没有使用方法来回叫通知
window.FirebasePlugin.onNotificationOpen
on server side i am posting like this, 在服务器端,我这样发布
def sendNotfMessage(def registrationIds,def body,def title){
def data = [:]
data['body']=body
data['title']=title
data['icon']="myicon"
data['sound']="mySound"
def postJson = [:]
postJson['priority'] = "high"
postJson['notification'] = data
postJson['registration_ids']=registrationIds
return sendFcmNotf(postJson)
}
def sendFcmNotf(def postJson){
HttpTransport transport = new NetHttpTransport()
HttpRequest request = transport.createRequestFactory().buildPostRequest(new GenericUrl("https://fcm.googleapis.com/fcm/send"), new JsonHttpContent(new JacksonFactory(), postJson));
HttpHeaders reqHeaders = new HttpHeaders()
reqHeaders.setAuthorization("key=${grailsApplication.config.android.fcm.api.key}")
reqHeaders.setAccept("application/json")
reqHeaders.setContentType("application/json")
request.setHeaders(reqHeaders)
request.setUnsuccessfulResponseHandler(new HttpBackOffUnsuccessfulResponseHandler(new ExponentialBackOff.Builder()
.setInitialIntervalMillis(500)
.setMaxElapsedTimeMillis(900000)
.setMaxIntervalMillis(6000)
.setMultiplier(1.5)
.setRandomizationFactor(0.5)
.build()
))
try {
HttpResponse response = request.execute();
InputStream is = response.getContent()
BufferedReader br = new BufferedReader(new InputStreamReader(is))
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
ObjectMapper mapper = new ObjectMapper()
Map<String, Object> responseMap = mapper.readValue(sb.toString(), new TypeReference<Map<String, Object>>(){})
// Process response JSON per https://firebase.google.com/docs/cloud-messaging/server#response
if(responseMap && (responseMap['failure'] != 0 || responseMap['canonical_ids'] != 0)){
if(responseMap['message_id'] && responseMap['registration_id']){
log.info "New push token, setting to ${responseMap['registration_id']}"
// TODO Notify backend that token has changed, i.e. update
}
}else{
def results = responseMap['results']
if(results){
results.each{
if(it['error']){
if(it['error'] == "NotRegistered"){
log.info 'NotRegistered, updating AppToken to null'
// TODO Notify backend this token is no longer valid, i.e. delete
}
}
}
}
}
return responseMap
}catch(HttpResponseException e){
log.error "Error: ${e.toString()}"
return (['SC' : e.getStatusCode(), 'M' : e.getStatusMessage() ])
}
}
}
i got it ,actually i miss to upload APNs certificate at 我知道了,实际上我想念在上载APNs证书
console.firebase.google.com
you can refer the link for more details. 您可以参考该链接以获取更多详细信息。 https://firebase.google.com/docs/cloud-messaging/ios/client ? https://firebase.google.com/docs/cloud-messaging/ios/client ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.