Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>With no other changes to the library, this works for me. It sidesteps CI a bit, but still allows you to load in APNS-PHP as a model:</p> <pre><code>&lt;?php if(!defined('BASEPATH')) exit('No direct script access allowed'); class Notification_model extends CI_Model { protected $apnsDir = ''; // ----------------------------------------------- /** * Setup some basic stuffs * @param void * @return void * @access public */ public function __construct() { parent::__construct(); /* get all the APNS files */ $this-&gt;apnsDir = $_SERVER['DOCUMENT_ROOT'].'/application/third_party/ApnsPHP/'; $this-&gt;_apns_req(); return; } /* /__construct() */ // ----------------------------------------------- /** * Will send the actual iOS notification to the user * @param $token string iOS device token * @param $msg string * @param $attrs array Key/value pairs to be sent as meta with APN * @return void * @access public */ private function send_ios($token=null, $msg=null, $attrs=array()) { if(!$token || !$msg) return; // Instantiate a new ApnsPHP_Push object $push = new ApnsPHP_Push( ApnsPHP_Abstract::ENVIRONMENT_SANDBOX, $this-&gt;apnsDir.'SSL/server_certificates_bundle_sandbox.pem' ); // Set the Provider Certificate passphrase // $push-&gt;setProviderCertificatePassphrase('tablecan29'); // Set the Root Certificate Autority to verify the Apple remote peer $push-&gt;setRootCertificationAuthority($this-&gt;apnsDir.'SSL/entrust_root_certification_authority.pem'); // Connect to the Apple Push Notification Service $push-&gt;connect(); // Instantiate a new Message with a single recipient $message = new ApnsPHP_Message($token); // Set a custom identifier. To get back this identifier use the getCustomIdentifier() method // over a ApnsPHP_Message object retrieved with the getErrors() message. $message-&gt;setCustomIdentifier("Message-Badge-3"); // Set badge icon to "3" // $message-&gt;setBadge(0); // Set a simple welcome text $message-&gt;setText($msg); // Play the default sound $message-&gt;setSound(); // Set custom properties if( is_array($attrs) &amp;&amp; count($attrs) ) { foreach( $attrs as $attr_key =&gt; $attr_val ) { $message-&gt;setCustomProperty($attr_key, $attr_val); } } // Set the expiry value - in seconds $message-&gt;setExpiry(120); // Add the message to the message queue $push-&gt;add($message); // Send all messages in the message queue $push-&gt;send(); // Disconnect from the Apple Push Notification Service $push-&gt;disconnect(); // Examine the error message container // $aErrorQueue = $push-&gt;getErrors(); // if (!empty($aErrorQueue)) { // var_dump($aErrorQueue); // } return TRUE; } /* /send_ios() */ // ----------------------------------------------- private function _apns_req() { require_once $this-&gt;apnsDir.'Abstract.php'; require_once $this-&gt;apnsDir.'Exception.php'; require_once $this-&gt;apnsDir.'Feedback.php'; require_once $this-&gt;apnsDir.'Message.php'; require_once $this-&gt;apnsDir.'Log/Interface.php'; require_once $this-&gt;apnsDir.'Log/Embedded.php'; require_once $this-&gt;apnsDir.'Message/Custom.php'; require_once $this-&gt;apnsDir.'Message/Exception.php'; require_once $this-&gt;apnsDir.'Push.php'; require_once $this-&gt;apnsDir.'Push/Exception.php'; require_once $this-&gt;apnsDir.'Push/Server.php'; require_once $this-&gt;apnsDir.'Push/Server/Exception.php'; return; } /* /_apns_req() */ } /* /Notification_model{} */ /* End of file notification_model.php */ /* Location: ./application/models/notification_model.php */ </code></pre> <p>Example usage:</p> <pre><code>$this-&gt;load-&gt;model('notification_model'); $this-&gt;notification_model-&gt;send_ios($token, 'Test Message', array('custom_var' =&gt; 'val')); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload