总结
豆包 AI 助手文章总结

apns-php

php中文网
发布: 2016-06-23 14:37:07
原创
2143人浏览过

sample_push.php<?php/** * @file * sample_push.php * * Push demo * * 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. * * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com) * @version $Id$ */// Adjust to your timezonedate_default_timezone_set('Europe/Rome');// Report all PHP errorserror_reporting(-1);// Using Autoload all classes are loaded on-demandrequire_once 'ApnsPHP/Autoload.php';// Instanciate a new ApnsPHP_Push object$push = new ApnsPHP_Push(        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,        'server_certificates_bundle_sandbox.pem');// Set the Root Certificate Autority to verify the Apple remote peer$push->setRootCertificationAuthority('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);}
登录后复制

 

立即学习PHP免费学习笔记(深入)”;

sample_feedback.php

<?php/** * @file * sample_feedback.php * * Feedback demo * * 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. * * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com) * @version $Id$ */// Adjust to your timezonedate_default_timezone_set('Europe/Rome');// Report all PHP errorserror_reporting(-1);// Using Autoload all classes are loaded on-demandrequire_once 'ApnsPHP/Autoload.php';// Instanciate a new ApnsPHP_Feedback object$feedback = new ApnsPHP_Feedback(        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,        'server_certificates_bundle_sandbox.pem');// Connect to the Apple Push Notification Feedback Service$feedback->connect();$aDeviceTokens = $feedback->receive();if (!empty($aDeviceTokens)) {        var_dump($aDeviceTokens);}// Disconnect from the Apple Push Notification Feedback Service$feedback->disconnect();
登录后复制

 

立即学习PHP免费学习笔记(深入)”;

sample_server.php

<?php/** * @file * sample_server.php * * Push server demo * * 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. * * @author (C) 2010 Aldo Armiento (aldo.armiento@gmail.com) * @version $Id$ */// Adjust to your timezonedate_default_timezone_set('Europe/Rome');// Report all PHP errorserror_reporting(-1);// Using Autoload all classes are loaded on-demandrequire_once 'ApnsPHP/Autoload.php';// Instanciate a new ApnsPHP_Push object$server = new ApnsPHP_Push_Server(        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,        'server_certificates_bundle_sandbox.pem');// Set the Root Certificate Autority to verify the Apple remote peer$server->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 <= 10) {                // Instantiate a new Message with a single recipient                $message = new ApnsPHP_Message('1e82db91c7ceddd72bf33d74ae052ac9c84a065b35148ac401388843106a7485');                // Set badge icon to "i"                $message->setBadge($i);                // Add the message to the message queue                $server->add($message);                $i++;        }        // Sleep a little...        usleep(200000);}
登录后复制

 

立即学习PHP免费学习笔记(深入)”;

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
登录后复制

 

立即学习PHP免费学习笔记(深入)”;

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
豆包 AI 助手文章总结
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号