Open risototh opened 4 years ago
@risototh yes this is known. Do you have time to contribute?
@seyfer not sure, if I have the time. Depends, on how much it will require. I only went around, when updating this library from the 2.0.0 version in our code ;D Maybe I can spent some hours on that, but I don't even know, what this library is for and how to test it...
We are running out of time here. Apple just wrote:
If you still send push notifications with the legacy binary protocol, make sure to upgrade to the APNs provider API as soon as possible. APNs will no longer support the legacy binary protocol after March 31, 2021.
@risototh Sir any update , i am not able to send push to apple anymore, it goes to android but not to ios , on same side it goes when i try from pushtry.com? @seyfer @kw-pr
To get the ball rolling, here is a quick implementation of an HTTP based adapter. It uses apple/apn-push. It’s probably not complete, probably has bugs and so on but it works for simple cases in my testing.
class ApnsHttp extends BaseAdapter
{
public function push(PushInterface $push): DeviceCollection
{
$certificate = new Certificate($this->getParameter('certificate'), $this->getParameter('passPhrase'));
$authenticator = new CertificateAuthenticator($certificate);
$builder = new Http20Builder($authenticator);
$sender = $builder->build();
$pushedDevices = new DeviceCollection();
/** @var DeviceInterface $device */
foreach ($push->getDevices() as $device) {
$receiver = new Receiver(new DeviceToken($device->getToken()), $this->getParameter('bundleId'));
try {
$sender->send($receiver, $this->toNotification($device, $push->getMessage()), $this->isDevelopmentEnvironment());
$push->addResponse($device, ['success' => true]);
$push->pushed();
$pushedDevices->add($device);
} catch (SendNotificationException $e) {
throw new PushException($e->getMessage(), null, $e);
}
}
return $pushedDevices;
}
private function toNotification(DeviceInterface $device, Message $message): Notification
{
$alert = (new Alert())
->withBody($message->getText())
->withTitle($message->getOption('title') ?? '')
->withLaunchImage($message->getOption('launchImage') ?? '');
if ($message->getOption('locKey')) {
$alert = $alert->withBodyLocalized(
new Localized($message->getOption('locKey'), $message->getOption('locArgs', []))
);
}
if ($message->getOption('actionLocKey')) {
$alert = $alert->withActionLocalized(
new Localized($message->getOption('actionLocKey'), $message->getOption('actionLocKeyArgs', []))
);
}
if ($message->getOption('titleLocKey')) {
$alert = $alert->withLocalizedTitle(
new Localized($message->getOption('titleLocKey'), $message->getOption('titleLocArgs', []))
);
}
$aps = (new Aps($alert))
->withSound($message->getOption('sound') ?? '')
->withContentAvailable($message->getOption('content-available', false))
->withMutableContent($message->getOption('mutable-content', false))
->withCategory($message->getOption('category') ?? '');
if ($message->hasOption('badge')) {
$aps = $aps->withBadge($message->getOption('badge') + $device->getParameter('badge', 0));
}
$payload = (new Payload($aps));
foreach ($message->getOption('custom', []) as $key => $value) {
$payload = $payload->withCustomData($key, $value);
}
return (new Notification($payload))
->withExpiration(
$message->getOption('expire') ? new Expiration(new DateTime($message->getOption('expire'))) : null
);
}
public function supports($token): bool
{
return ctype_xdigit($token);
}
public function getDefinedParameters(): array
{
return [];
}
public function getDefaultParameters(): array
{
return ['passPhrase' => ''];
}
public function getRequiredParameters(): array
{
return ['certificate', 'bundleId'];
}
}
Composer outputs: