All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pubnub.api.PnApnsMessage Maven / Gradle / Ivy

Go to download

PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter second!

There is a newer version: 3.7.10
Show newest version
package com.pubnub.api;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * Message object for APNS
 * 
 * @author Pubnub
 *
 */
public class PnApnsMessage extends JSONObject {

    /**
     * Constructor for APNS message object
     */
    public PnApnsMessage() {
        super();
    }

    private JSONObject getAps() {
        JSONObject aps = null;
        try {
            aps = (JSONObject) this.get("aps");
        } catch (JSONException e) {

        }

        if (aps == null) {
            aps = new JSONObject();
            try {
                this.put("aps", aps);
            } catch (JSONException e) {

            }
        }
        return aps;
    }

    /**
     * Set value of APS alert
     * 
     * @param alert
     *            String to be set as alert value for APNS message
     */
    public void setApsAlert(String alert) {

        try {
            JSONObject aps = (JSONObject) getAps();
            aps.put("alert", alert);
        } catch (JSONException e) {

        }

    }

    /**
     * Set value of APS badge
     * 
     * @param badge
     *            int to be set as badge value for APNS message
     */
    public void setApsBadge(int badge) {
        try {
            JSONObject aps = (JSONObject) (JSONObject) getAps();
            aps.put("badge", badge);
        } catch (JSONException e) {

        }

    }

    /**
     * Set value of APS sound
     * 
     * @param sound
     *            String to be set as sound value for APNS message
     */
    public void setApsSound(String sound) {

        try {
            JSONObject aps = (JSONObject) getAps();
            aps.put("sound", sound);
        } catch (JSONException e) {

        }

    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy