Search in sources :

Example 1 with PayloadBuilder

use of com.notnoop.apns.PayloadBuilder in project ranch by heisedebaise.

the class IosSenderImpl method send.

@Override
public boolean send(PushModel push, String receiver, JSONObject args) {
    IosModel ios = iosService.find(push.getAppCode(), args.getIntValue("destination"));
    if (ios == null)
        return false;
    ApnsService service = iosService.getApnsService(ios.getAppCode(), ios.getDestination());
    if (service == null)
        return false;
    PayloadBuilder payloadBuilder = APNS.newPayload();
    payloadBuilder.alertTitle(pushService.parse(PushService.Type.Subject, push.getKey(), push.getSubject(), args));
    payloadBuilder.alertBody(pushService.parse(PushService.Type.Content, push.getKey(), push.getContent(), args));
    payloadBuilder.badge((json.containsKey(args, "badge") ? args.getIntValue("badge") : 1) + 1);
    payloadBuilder.sound(json.containsKey(args, "sound") ? args.getString("sound") : "default");
    service.push(receiver, payloadBuilder.build());
    return true;
}
Also used : PayloadBuilder(com.notnoop.apns.PayloadBuilder) IosModel(org.lpw.ranch.push.ios.IosModel) ApnsService(com.notnoop.apns.ApnsService)

Example 2 with PayloadBuilder

use of com.notnoop.apns.PayloadBuilder in project onebusaway-application-modules by camsys.

the class AlarmServiceImpl method getDataAsApnsPayload.

private String getDataAsApnsPayload(String alarmId, JSONObject data) {
    PayloadBuilder b = PayloadBuilder.newPayload();
    b.customField("alarmId", alarmId);
    try {
        if (data.has("actionKey"))
            b.actionKey(data.getString("actionKey"));
        if (data.has("alertBody"))
            b.alertBody(data.getString("alertBody"));
        if (data.has("badge"))
            b.badge(data.getInt("badge"));
        if (data.has("sound"))
            b.sound(data.getString("sound"));
    } catch (JSONException e) {
        throw new InvalidArgumentServiceException("data", e.getMessage());
    }
    return b.build();
}
Also used : PayloadBuilder(com.notnoop.apns.PayloadBuilder) InvalidArgumentServiceException(org.onebusaway.exceptions.InvalidArgumentServiceException) JSONException(org.json.JSONException)

Aggregations

PayloadBuilder (com.notnoop.apns.PayloadBuilder)2 ApnsService (com.notnoop.apns.ApnsService)1 JSONException (org.json.JSONException)1 IosModel (org.lpw.ranch.push.ios.IosModel)1 InvalidArgumentServiceException (org.onebusaway.exceptions.InvalidArgumentServiceException)1