I am working on someone's code. there is one function in code.
it is like following:
function send_notification($device_token)
{
$apn = new APN();
$apn->payloadMethod = 'enhance'; // you can turn on this method for debuggin purpose
$apn->connectToPush();
............................
............................
}
then inside foreach loop, he call the function.
foreach($alluser as $user)
{
send_notification($user['device_token']);
}
now if i run above code then it says APN Failed to connect: Something wrong with context
.
so i changed few things in code.
$apn = new APN();
foreach($alluser as $user)
{
$apn->payloadMethod = 'enhance'; // you can turn on this method for debuggin purpose
$apn->connectToPush();
............................
............................
}
i create the object of class outside of foreach loop then it is working.
but the wrost thing is, i have to write above code in each place (this page contain other foreach).
So how can i solve above problem in a smart way?
FULL CODE (Just some part)
<?php
foreach($alluser as $user)
{
send_notification($user['device_token']);
}
function send_notification($device_token)
{
$apn = new APN();
$apn->payloadMethod = 'enhance'; // you can turn on this method for debuggin purpose
$apn->connectToPush();
............................
............................
}
?>
Sidenote: What i am trying to know is when i create new instance of class each time then why it is not working?