clevis / push-notifications
移动设备的推送通知/消息
v1.0.1
2014-08-24 14:15 UTC
Requires
- php: >=5.3.0
- kriswallsmith/buzz: ~0.12
- nette/di: ~2.2.0
This package is not auto-updated.
Last update: 2024-09-24 02:52:36 UTC
README
一个允许向移动设备发送推送通知的包。目前支持Android(C2DM、GCM)、Blackberry和iOS设备。
安装
要在您的Nette项目中使用此包,请将以下内容添加到您的composer.json
{ "require": { "clevis/push-notifications": "~0.1-beta" } }
并在配置中启用它
extensions: pushNotifications: Clevis\PushNotifications\DI\PushNotificationsExtension pushNotifications: android: c2dm: username: password: source: gcm: apiKey: apple: sandbox: # boolean pem: # path to certificate passphrase:
注意:如果您使用的是Windows,可能需要将Android GCM的use_multi_curl
标志设置为false,以确保GCM消息正确发送。
使用方法
以下是一个示例,说明如何将第一条消息推送到iOS设备,我们假设您已正确设置配置
use Clevis\PushNotifications\Message\iOSMessage;
use Clevis\PushNotifications\Notifications;
class Service
{
/**
* @var Notifications
*/
protected $sender;
public function __construct(Notifications $sender)
{
$this->sender = $sender;
}
public function sendPushNotificationExample()
{
$message = new iOSMessage();
$message->setMessage('Oh my! A push notification!');
$message->setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5fb448fe505eb4asdfef8595a7');
$this->sender->send($message);
}
}
发送方法将检测消息类型,如果您传递一个AndroidMessage
,它将自动通过C2DM/GCM服务器发送,同样适用于Mac和Blackberry。
Android消息
由于C2DM和GCM仍然可用,AndroidMessage
类上有一个小标志,可以切换发送到哪个服务。如下使用:
use Clevis\PushNotificationsBundle\Message\AndroidMessage; $message = new AndroidMessage(); $message->setGCM(true);
将消息作为GCM消息发送,而不是C2DM。
iOS反馈服务
Apple推送通知服务还公开了一个反馈服务,您可以从中获取有关失败推送通知的信息 - 更多详细信息请参阅此处。
此服务包含在包中。以下代码演示了如何从服务中检索数据
$feedbackService = $container->get("rms_push_notifications.ios.feedback"); $uuids = $feedbackService->getDeviceUUIDs();
在此,$uuids
包含一个包含时间戳、令牌长度和设备UUID的Feedback对象数组。
Apple建议您每天轮询此服务。