首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JAVAPNS 2.2成功推送但未在设备上接收

JAVAPNS 2.2成功推送但未在设备上接收
EN

Stack Overflow用户
提问于 2012-07-05 18:20:11
回答 1查看 7.6K关注 0票数 3

在此处输入代码我尝试使用JAVAPNS 2.2从Java推送

这是我的代码

代码语言:javascript
复制
import java.util.*;
import org.apache.log4j.BasicConfigurator;
import org.json.JSONException;
import javapns.*;
import javapns.communication.exceptions.CommunicationException;
import javapns.communication.exceptions.KeystoreException;
import javapns.notification.PushNotificationPayload;
import javapns.notification.PushedNotification;
import javapns.notification.ResponsePacket;



public class Test {

/**
 * @param args
 */
public static void main(String[] args) {

    BasicConfigurator.configure();

    try {

        PushNotificationPayload payload = PushNotificationPayload.complex();

        payload.addAlert("Hello World");
        payload.addBadge(1);
        payload.addSound("default");
        payload.addCustomDictionary("id", "1");


        System.out.println(payload.toString());
        List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", true, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");

        for (PushedNotification NOTIFICATION : NOTIFICATIONS) {
            if (NOTIFICATION.isSuccessful()) {
                    /* APPLE ACCEPTED THE NOTIFICATION AND SHOULD DELIVER IT */  
                    System.out.println("PUSH NOTIFICATION SENT SUCCESSFULLY TO: " +
                                                    NOTIFICATION.getDevice().getToken());
                    /* STILL NEED TO QUERY THE FEEDBACK SERVICE REGULARLY */  
            } 
            else {
                    String INVALIDTOKEN = NOTIFICATION.getDevice().getToken();
                    /* ADD CODE HERE TO REMOVE INVALIDTOKEN FROM YOUR DATABASE */  

                    /* FIND OUT MORE ABOUT WHAT THE PROBLEM WAS */  
                    Exception THEPROBLEM = NOTIFICATION.getException();
                    THEPROBLEM.printStackTrace();

                    /* IF THE PROBLEM WAS AN ERROR-RESPONSE PACKET RETURNED BY APPLE, GET IT */  
                    ResponsePacket THEERRORRESPONSE = NOTIFICATION.getResponse();
                    if (THEERRORRESPONSE != null) {
                            System.out.println(THEERRORRESPONSE.getMessage());
                    }
            }
      }


    } catch (CommunicationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeystoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
}

库成功发送,但我的设备从未收到推送。我已经尝试了我的设备的许多令牌,甚至尝试重新生成证书.12,但仍然没有用。

日志

代码语言:javascript
复制
0 [main] DEBUG javapns.notification.Payload  - Adding alert [Hello World]

1 [main] DEBUG javapns.notification.Payload  - Adding badge [1]

1 [main] DEBUG javapns.notification.Payload  - Adding sound [default]

1 [main] DEBUG javapns.notification.Payload  - Adding custom Dictionary [id] = [1]

{"id":"1","aps":{"sound":"default","alert":"Hello World","badge":1}}

292 [main] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocketFactory

341 [main] DEBUG javapns.communication.ConnectionToAppleServer  - Creating SSLSocket to gateway.push.apple.com:2195

972 [main] DEBUG javapns.notification.PushNotificationManager  - Initialized Connection to 
Host: [gateway.push.apple.com] Port: [2195]: 1923e91b[SSL_NULL_WITH_NULL_NULL: Socket[addr=gateway.push.apple.com/17.149.35.173,port=2195,localport=65225]]

974 [main] DEBUG javapns.notification.PushNotificationManager  - Building Raw message from deviceToken and payload

974 [main] DEBUG javapns.notification.PushNotificationManager  - Built raw message ID 1 of total length 113

974 [main] DEBUG javapns.notification.PushNotificationManager  - Attempting to send notification: {"id":"1","aps":{"sound":"default","alert":"Hello World","badge":1}}

974 [main] DEBUG javapns.notification.PushNotificationManager  -   to device: AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D

1743 [main] DEBUG javapns.notification.PushNotificationManager  - Flushing

1743 [main] DEBUG javapns.notification.PushNotificationManager  - At this point, the entire 113-bytes message has been streamed out successfully through the SSL connection

1743 [main] DEBUG javapns.notification.PushNotificationManager  - Notification sent on first attempt

1743 [main] DEBUG javapns.notification.PushNotificationManager  - Reading responses

1744 [main] DEBUG javapns.notification.PushNotificationManager  - Closing connection
PUSH NOTIFICATION SENT SUCCESSFULLY TO: AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D

有谁知道吗?

EN

回答 1

Stack Overflow用户

发布于 2015-01-23 14:26:29

这一行应该

代码语言:javascript
复制
List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", true, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");

应该改成这样

代码语言:javascript
复制
List<PushedNotification> NOTIFICATIONS = Push.payload(payload, "D:\\keystore1.p12", "123456", false, "AA67F2F18586D2C83398F9E5E5BE8BA1CD3FF80257CC74BACF2938CE144BA71D");
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11342293

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档