Skip to content
This repository has been archived by the owner on Nov 15, 2020. It is now read-only.

malcommac/DMAPNServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

DMAPNServer

####Apple APN Push Notification & Feedback Provider

Created by Daniele Margutti - daniele.margutti@gmail.com.

INTRODUCTION

This is a set of open source PHP classes to interact with the Apple Push Notification service for iOS and OS X (Mountain Lion). I've wrote it for my own needs and due to some limitations on my virtual server platform it does not support multiple concurrent threads sending (okay in fact i'm talking about multiple forked processes). It's very simple to use.

GENERATE A PUSH CERTIFICATE

  • Login into the iOS or OSX Developer Program Portal from this page
  • Choose or create a new App ID for your application (without a wildcard): for example com.danielemargutti.romapocket.
  • Click Configure link next to your AppID and then click on the button to start the wizard to generate a new push SSL certificate (you can create two kinds of certificates, sandbox/development can be used during program development, production is used when you want to publish your app on appstore/adhoc). More at Apple Docs
  • Download your certificate (it's a .cer file) then double click on it. Your certificate will be imported in your Mac Keychain Assistant (/Applications/Utilities/Keychain Access).
  • Find your certificate in certificate's list, then expand it: select it and it's private key then control click to show 'Export 2 elements…'; you will save a new .p12 certificate
  • Now you need to convert .p12 certificate to PEM. You can use openssl from terminal (openssl pkcs12 -in p12-certificate-path -out pem-file-destination-path -nodes -clcerts) or this web utility
  • You have your PEM certificate! Now come back to Developer Program and generate your Development/Distribution provisioning profile for your app. Follow Local and Push Notification Programming Guide/Registering for Remote Notifications and implement client side part of it.

HOW TO SEND A PUSH WITH DMAPNServer

$APN = new DMAPNPushServer(false);
$APN->setCertificate("production/sandbox_cert.pem","password-if-any");
$message = new DMAPNMessage("device_uuid","message");
$APN->addMessage($message);
$APN->connect();
$APN->sendMessages();

HOW TO GET FEEDBACK FROM DMAPNServer

Sometimes APNs might attempt to deliver notifications for an application on a device, but the device may repeatedly refuse delivery because there is no target application.

This often happens when the user has uninstalled the application. In these cases, APNs informs the provider through a feedback service that the provider connects with.

The feedback service maintains a list of devices per application for which there were recent, repeated failed attempts to deliver notifications. The provider should obtain this list of devices and stop sending notifications to them.

$APNFeedback = new DMAPNFeedbackService(false);
$APNFeedback->setCertificate("production_cert.pem","");
$unregistered_devices = $APNFeedback->unregisteredDevices();
if ($unregistered_devices == false)
echo "failed to query feedback server";
else
echo vardump($unregistered_devices);

About

APN - Apple Push Notification Server in PHP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages