notnoop / java-apns

Java Apple Push Notification Service Provider
notnoop.github.com/java-apns
BSD 3-Clause "New" or "Revised" License
1.8k stars 658 forks source link

Add support for custom APS properties #344

Open raderio opened 7 years ago

raderio commented 7 years ago

Sometimes Apple can add some new properties to APS object. In order to be able to use that new properties as soon as possible it will be good to add support for custom APS properties.

For example now we can add properties to payload

APNS.newPayload()
    .customField("name", "John")
    ...

How will be to add properties to APS

APNS.newPayload()
    .customAPSField("mutable_content", 1)
    ...
raderio commented 7 years ago

This also will be useful not to wait to add mutable content properties

And will fix https://github.com/notnoop/java-apns/issues/321 https://github.com/notnoop/java-apns/issues/328

ovictorpinto commented 6 years ago

I make a hook to "intercept" the payload generated:

String payload = builderPayload.build();
try {
    ObjectMapper mapper = new ObjectMapper();
    JavaType type = mapper.getTypeFactory().constructParametricType(Map.class, String.class, Object.class);
    Map<String, Object> root = mapper.readValue(payload, type);
    Map<String, Object> apns = (Map<String, Object>) root.get("aps");
    apns.put("apns-collapse-id", mensagemTO.getIdFuncionalidade());
    payload = mapper.writeValueAsString(root);
}catch (Exception e){
    logger.error("Montando mensagem", e);
}
keilon commented 6 years ago

As https://stackoverflow.com/questions/44560851/apns-collapse-id-not-merging-multiple-notifications-ios-10 said, "apns-collapse-id" is NOT supported in legacy binary interface, does it really work? @ovictorpinto

ovictorpinto commented 6 years ago

@keilon collapse-id don't work this way. But the hook to insert a property works =]