ID not integer... EasyAPNS
I have a method that get's all devices that share a specific ID. Foreach of those device UID's, I am trying to send a APN (Apple Push Notification) using the easyAPN's class.
The method that is having the problem is $apns->newMessage($id);
It seems to think I am not passing a valid integer for $id.
The $id is an array like so Array ( [0] => 1 )
I have also tried passing just the value of the array like so $apns->newMessage($id[0]).
No matter what I do.. I keep getting this error...
"Notice: TO id was not an integer. 1) Messages_model::send_apns -> File: sendMessage.php (line 28) 2) APNS::queueMessage -> File: messages_model.php (line 195) 3) APNS::_triggerError -> File: class_APN开发者_运维百科S.php (line 599)"
Here is my method... please let me know where I've gone wrong with the $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";
}
}
Try to convert $id to integer:
...
foreach ($pids as $pid) {
$id = intval($pid['pid']);
print_r($id);
//Send APN
$apns->newMessage($id);
...
精彩评论