Jump to content

php easyAPN's not an integer!


petroz

Recommended Posts

 

0

down vote

favorite

Hi Guys!

 

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_APNS.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";
	}



}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.