sample_push.phpsetrootcertificationauthority('entrust_root_certification_authority.pem');// connect to the apple push notification service$push->connect();// instantiate a new message with a single recipient$message = new apnsphp_message('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');// set a custom identifier. to get back this identifier use the getcustomidentifier() method// over a apnsphp_message object retrieved with the geterrors() message.$message->setcustomidentifier(message-badge-3);// set badge icon to 3$message->setbadge(3);// set a simple welcome text$message->settext('hello apns-enabled device!');// play the default sound$message->setsound();// set a custom property$message->setcustomproperty('acme2', array('bang', 'whiz'));// set another custom property$message->setcustomproperty('acme3', array('bing', 'bong'));// set the expiry value to 30 seconds$message->setexpiry(30);// add the message to the message queue$push->add($message);// send all messages in the message queue$push->send();// disconnect from the apple push notification service$push->disconnect();// examine the error message container$aerrorqueue = $push->geterrors();if (!empty($aerrorqueue)) { var_dump($aerrorqueue);}
sample_feedback.php
connect();$adevicetokens = $feedback->receive();if (!empty($adevicetokens)) { var_dump($adevicetokens);}// disconnect from the apple push notification feedback service$feedback->disconnect();
sample_server.php
setrootcertificationauthority('entrust_root_certification_authority.pem');// set the number of concurrent processes$server->setprocesses(2);// starts the server forking the new processes$server->start();// main loop...$i = 1;while ($server->run()) { // check the error queue $aerrorqueue = $server->geterrors(); if (!empty($aerrorqueue)) { // do somethings with this error messages... var_dump($aerrorqueue); } // send 10 messages if ($i setbadge($i); // add the message to the message queue $server->add($message); $i++; } // sleep a little... usleep(200000);}
introduction to send push notifications to a device, you need a device token. device token is generated by apple from device id and application id, so this is unique per device and per application.
deprecated please, see the objective-c demo project at http://code.google.com/p/apns-php/source/browse/trunk/objective-c%20demo
code /** * @file * application delegate implementation. * * license * * this source file is subject to the new bsd license that is bundled * with this package in the file license.txt. * it is also available through the world-wide-web at this url: * http://code.google.com/p/apns-php/wiki/license * if you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to aldo.armiento@gmail.com so we can send you a copy immediately. * * @version $id$ */#import appdelegate.h@implementation appdelegate@synthesize window;#pragma mark -#pragma mark application delegate- (void)applicationdidfinishlaunching:(uiapplication *)application { [window makekeyandvisible]; #if !target_iphone_simulator [application registerforremotenotificationtypes: uiremotenotificationtypealert | uiremotenotificationtypebadge | uiremotenotificationtypesound]; #endif}#pragma mark -#pragma mark remote notifications- (void)application:(uiapplication *)application didregisterforremotenotificationswithdevicetoken:(nsdata *)devicetoken { // you can send here, for example, an asynchronous http request to your web-server to store this devicetoken remotely. nslog(@did register for remote notifications: %@, devicetoken);}- (void)application:(uiapplication *)application didfailtoregisterforremotenotificationswitherror:(nserror *)error { nslog(@fail to register for remote notifications: %@, error);}#pragma mark -#pragma mark memory management/** * deallocates the memory occupied. */- (void)dealloc { [window release]; [super dealloc];}@end