HOWTO remove device tokens received by Apple APNS feedback

后端 未结 6 2008
慢半拍i
慢半拍i 2021-02-09 19:39

I am successfully fetching Apple APNS feedback data via PHP. The structure that I am getting (after some processing) looks something like this:

timestamp

device

6条回答
  •  佛祖请我去吃肉
    2021-02-09 20:07

    A timestamp (as a four-byte time_t value) indicating when APNs determined that the app no longer exists on the device. This value, which is in network order, represents the seconds since 12:00 midnight on January 1, 1970 UTC.

    you can compare it with your table's last insert time and then remove the invalid token from db, In my case i am using mysql and php for sever side

    $sql="SELECT insert_time from device_tokens ORDER BY insert_time DESC LIMIT 1";
    

    it will return last updated time from db and then i just convert it into epoch timestamp by using

    $sql1="SELECT UNIX_TIMESTAMP(' $timestamp')";
    

    and finally i just compare it with apns feedback timestamp like this

    if($inactive_Timestamp>$dbTime_stamp)
      {
    foreach ($apnsfeedback_tokens as $key => $value) {
      # code...
    
      $inactive_Token=$value['devtoken'];
    
     $sql= "DELETE FROM device_tokens WHERE device_token='$inactive_Token'";
    
    
    if ($conn->query($sql) === TRUE) {
        echo "Record deleted successfully";
    } else {
        echo "Error deleting record: " . $conn->error;
    }
    

提交回复
热议问题