always received success response even after two week uninstalled app

68 views
Skip to first unread message

hyun woo lee

unread,
Oct 27, 2020, 10:18:37 PM10/27/20
to pushy

when I tried this lib, send push works fine

However, I always received success response even after two week uninstalled app

how can I get uninstalled fail or unregistered token error?(400 or 410 error)


please see my code


public class ApnsSender {

private static final Logger logger = LoggerFactory.getLogger(ApnsSender.class);

public interface ApnsCallbacks {

void onSuccess(ApnsData apnsData);

void onFail(ApnsData apnsData);

void onFailNeedRemoveToken(ApnsData apnsData);

}

public static final String Enter_TeamName = "";

public static final String Enter_KeyID = "";

public static final String Store_TeamName = "";

public static final String Store_KeyID = "";

public void sendApns(String bundleId, boolean isDevelopmentMode, String certPath, String certFileName, ApnsData apnsData, ApnsCallbacks callback) {

ApnsClient apnsClient = null;

try {

String server = isDevelopmentMode ? ApnsClientBuilder.DEVELOPMENT_APNS_HOST : ApnsClientBuilder.PRODUCTION_APNS_HOST;

String teamName = certFileName.startsWith("Enter") ? Enter_TeamName : Store_TeamName;

String keyId = certFileName.startsWith("Enter") ? Enter_KeyID : Store_KeyID;

apnsClient = new ApnsClientBuilder()

.setApnsServer(server)

.setSigningKey(ApnsSigningKey.loadFromPkcs8File(new File(certPath), teamName, keyId))

.build();

}catch (SSLException e) {

e.printStackTrace();

logger.error(e.getMessage());

} catch (IOException e) {

e.printStackTrace();

logger.error(e.getMessage());

}catch (Exception e) {

e.printStackTrace();

logger.error(e.getMessage());

}

if(apnsClient == null) {

logger.error("push client create error!!!!!!!!");

return;

}

SimpleApnsPushNotification push;

ApnsPayloadBuilder payloadBuilder = new SimpleApnsPayloadBuilder();

payloadBuilder.setAlertBody(apnsData.message);

payloadBuilder.setBadgeNumber(apnsData.badgeCount);

push = new SimpleApnsPushNotification(apnsData.deviceToken, bundleId, payloadBuilder.build());

PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendNotificationFuture 

= apnsClient.sendNotification(push);

   

PushNotificationResponse<SimpleApnsPushNotification> pushNotificationResponse;

try {

pushNotificationResponse = sendNotificationFuture.get();

//always success response...

    if (!pushNotificationResponse.isAccepted()) {

        System.out.println("Notification rejected by the APNs gateway: " +

                pushNotificationResponse.getRejectionReason());

        pushNotificationResponse.getTokenInvalidationTimestamp().ifPresent(timestamp -> {

            System.out.println("\t…and the token is invalid as of " + timestamp);

        });

        apnsClient.close();

        callback.onFailNeedRemoveToken(apnsData);

        return;

    }

    System.out.println("Push notification accepted by APNs gateway.");

    apnsClient.close();

        callback.onSuccess(apnsData);    

} catch (InterruptedException | ExecutionException e) {

apnsClient.close();

callback.onFail(apnsData);

logger.error("Failed to send push notification.");

e.printStackTrace();

}

}

}

Petr Dvořák

unread,
Oct 28, 2020, 3:38:24 AM10/28/20
to pushy
Hello, this is not a question that the author of this library can answer. Pushy returns error codes correctly as it receives it from APNS. As for when the token expires, this is completely on Apple / APNS service. Please read a bit on how APNS works and what error codes are returned when: https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html

In your code, I would suggest switching from ".get" to ".whenCompleteAsync" async implementation to improve performance.

Petr D.
Reply all
Reply to author
Forward
0 new messages