简体   繁体   中英

Sending Push Notification to device using parse4j in java

I am using parse4j library for server side coding and on client side I have iOS device. Now I want to send the push notification from my web browser page I developed in JAVA in which I am using parse4j library to communicate with iOS device through Parse cloud. I am using gwt for coding the server side.

public void sendPushtoIOS() {
    Parse.initialize("appId", "restApiId");
    ParsePush parsePushObj = new ParsePush();
    parsePushObj.sendInBackground("hello from server",null);
}

I am trying to send the notification with the above code, but nothing happens and iOS device doesn't receive any notification. Please could someone guide the code I written is correct or not, If not, how can I send the notification then?

try {
    String rawJSON = "{\"aps\":{\"alert\":\""+"your message"+"\"},\"alerts\":{\"others\":\""+others+"\"}}";
    PushNotificationPayload payload=PushNotificationPayload.fromJSON(rawJSON);
    Push.payload(payload, "path of certificate.p12", password,false, appleDeviceToken);
}
catch (Exception e) {

}

As far as I understand correct, you are using the Parse4j library to send Push Notification. Did you control the current version of parse4j if it can send Push notification? Or it is pending enhancement? One suggestion; in order to send push notification write a cloud code and trigger this cloud code from parse4j. Then cloud code will send the Push notification.

Hope this helps, Regards.

This library works fine. You can check pushes in parse dashboard, most likely you collected push requests. The only problem was that library works with channels. Maybe you do not set channels. If you want to work with conditions, add this lines of code in library

JSONObject local = new JSONObject();
local.put("deviceType", "android");
data.put("where", local);

and remove

data.put("channel", "");
data.put("channels", new JSONArray(this.channelSet));

all of these changes must be done in method getJSONData() in class ParsePush

instead of android you can set your devices

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM