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
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
console.firebase.google.com
you can refer the link for more details. https://firebase.google.com/docs/cloud-messaging/ios/client ?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.