edamov / pushok

PHP client for Apple Push Notification Service (APNs) - Send push notifications to iOS using the new APNs HTTP/2 protocol with token-based (JWT with p8 private key)
MIT License
369 stars 119 forks source link

APNS Feedback service #67

Closed basiljohntme closed 4 years ago

basiljohntme commented 4 years ago

Thanks for this great library. It works like a charm. I just wondered about the 410 error code. I have sent a push notification successfully to a device and later uninstalled App, but still getting 200 response.

Please let me know how can I can get the 410 response code.

edamov commented 4 years ago

I don't have any ideas about the 200 response. It should be 410 according to APNS documentation. Maybe try with another device or try to wait for a few minutes after uninstalling the App.

basiljohntme commented 4 years ago

Still, its getting 200 response even after waited for a day. I will continue to use the legacy feedback service for invalidating the uninstalled App token.

isayeter commented 4 years ago

any update on this issue? @basiljohntme how did you connected to feedback server with .p8 file?

basiljohntme commented 4 years ago

@fattalgazi For connecting to the feedback service, I am not using this library. I am using below legacy way, // Create stream context. $stream_context = stream_context_create(); // Set the certificate to be used. stream_context_set_option($stream_context, 'ssl', 'local_cert', 'phn_application/cert/' . $this->apple_cert_to_use); stream_context_set_option($stream_context, 'ssl', 'passphrase', $this->apple_push_phrase);

    $apns = stream_socket_client($this->apple_feedback_url, $errr_code, $err_message, 60, STREAM_CLIENT_CONNECT, $stream_context);
    if (!$apns) 
    {
        log_message("error", "APN failed to connect to apple feedback service " . $error_message);
    }
    else
    {
        echo "Connected to Apple feedback service, reading data...\n";
        $feedback_tokens = array();
        // And read the data on the connection:
        while(!feof($apns)) 
        {
            $data = fread($apns, 38);
            if (strlen($data)) 
            {
                $feedback_tokens[] = unpack("N1timestamp/n1length/H*devtoken", $data);
            }           
        }

        // Close the connection to the feedback server.
        fclose($apns);
        echo "Closed feedback connection\n";

        // So if have some tokens then we need to get the info in to a format which is useful to send back to loyalty.
        if ($feedback_tokens)
        {
            echo "-Invalidate\n";
        }
        else
        {
            echo "- No devices have unregistered\n";
        }
    }