ID不是整数... EasyAPNS

时间:2010-12-03 22:51:49

标签: php iphone mysql

我有一种方法可以获得共享特定ID的所有设备。对于那些设备UID,我试图使用easyAPN的类发送APN(Apple推送通知)。

遇到问题的方法是$ apns-> newMessage($ id);

似乎我认为我没有为$ id传递有效的整数。

$ id是一个类似于Array([0] => 1)

的数组

我也试过传递数组的值,如$ apns-> newMessage($ id [0])。

无论我做什么......我一直收到这个错误......

“注意:TO id不是整数.1)Messages_model :: send_apns - >文件:sendMessage.php(第28行)2)APNS :: queueMessage - >文件:messages_model.php(第195行)3 )APNS :: _ triggerError - >文件:class_APNS.php(第599行)“

这是我的方法...请让我知道$ id的错误。

function send_apns($data)
{
    include 'apn_classes/class_DbConnect.php';
    include 'apn_classes/class_APNS.php';

    $message = new Messages_model();
    $db = new DbConnect();
    $db->show_errors();
    $apns = new APNS($db);

    //get uid's for aid
    $sql = "SELECT `devices`.`uid` FROM `devices` WHERE `devices`.`aid` = '".$data['target']."'";
    //echo $sql;
    $query = mysql_query($sql);
    if(mysql_num_rows($query))
    {
    while($uid_data = mysql_fetch_array($query))
        $uids[] = array(
            "uid" => $uid_data['uid']
        );
    }

    //make sure there is a uid
    if(!empty($uids))
    {
        //check the device apn pid
        foreach($uids as $uid)
        {
            $sql = "SELECT `apns_devices`.`pid` FROM `apns_devices` WHERE `apns_devices`.`deviceuid` = '".$uid['uid']."'";
            //echo "$sql";
            $query = mysql_query($sql);
            if(mysql_num_rows($query) > 0)
            {
                while($pid_data = mysql_fetch_array($query))
                {
                    $pids[] = array(
                        "pid" => $pid_data['pid'],
                    );

                    if(!empty($pids))
                    {
                        foreach ($pids as $pid)
                        {
                            $id = array($pid['pid']);
                            print_r($id);
                            //Send APN
                            $apns->newMessage($id[0]);
                            $apns->addMessageBadge(128);
                            $apns->addMessageAlert($data['message']);
                            $apns->addMessageSound('chime');
                            //$apns->addMessageCustom('acme2');
                            $apns->queueMessage();
                            $apns->processQueue();
                        }
                    }                   
                }
            }
        }

    }
    else 
    {
        echo "Device Does not Exist";
    }



}

1 个答案:

答案 0 :(得分:1)

尝试将$ id转换为整数:

...
foreach ($pids as $pid) {
  $id = intval($pid['pid']);
  print_r($id);
  //Send APN
  $apns->newMessage($id);
  ...