apns php demo,apns-php

这篇博客介绍了如何使用Apns-PHP库来实现Apple Push Notification Service(APNs)的推送通知和反馈服务。首先,设置根证书,连接到APNs服务并创建消息,包括设置badge、自定义标识符和文本内容。然后,发送消息并检查错误队列。在反馈服务部分,接收设备令牌并断开连接。最后,展示了如何启动多进程服务器发送消息并处理错误。代码示例涵盖了推送通知的完整流程。
摘要由CSDN通过智能技术生成

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 <= 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);}

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中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。 经导师精心指导并认可、获 98 分的毕业设计项目!【项目资源】:微信小程序。【项目说明】:聚焦计算机相关专业毕设及实战操练,可作课程设计与期末大作业,含全部源码,能直用于毕设,经严格调试,运行有保障!【项目服务】:有任何使用上的问题,欢迎随时与博主沟通,博主会及时解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值