APNS首次写入后关闭连接

After my first write to the socket, APNS closes the connection! The first notification sends perfectly fine, but the second one fails because of EOF.

I've attached a small snippet of my code for sending a notification. Let me know if I should include more. Thanks for the help!

func (notificationService *NotificationService) Send(deviceToken []byte, payload *Payload, expiration time.Time, priority int) (uint32, error) {
    apnsBinary, err := createApnsBinary(deviceToken, payload, notificationIdentifier, expiration, priority)
    if err != nil {
        return 0, err
    }

    _, err = notificationService.connection.Write(apnsBinary)
    if err != nil {
        return 0, err
    }

    responseBytes := make([]byte, 6, 6)
    bytesRead, err := notificationService.connection.Read(responseBytes)
    if err != nil && err != io.EOF {
        return 0, err
    } else if bytesRead > 0 {
        errorResponseInHex := hex.EncodeToString(responseBytes[:bytesRead])
        return 0, fmt.Errorf("Received bad response %s", errorResponseInHex)
    }

    if err == io.EOF {
        fmt.Println("BOO NOT AGAIN!!")
    }

    return notificationIdentifier, nil
}

If the first message was delivered successfully and the second failed, it is more likely the connection was closed due to a problem in the second message. The most likely problem would be an invalid device token (which could happen if you use a development token when pushing to the production APNS env, or vice versa).

Try to send only the second message, and see if it works. If not, the problem is definitely in that message.