richsage / rms-push-notifications-bundle
移动设备的推送通知/消息
Requires
- php: >=5.3.0
- kriswallsmith/buzz: *
- psr/log: ^1.0
Requires (Dev)
- symfony/symfony: ^2.0 || ^3.0
Suggests
- symfony/symfony: To use as a bundle
This package is auto-updated.
Last update: 2021-06-23 20:56:05 UTC
README
允许向移动设备发送推送通知的包。目前支持Android(C2DM、GCM)、Blackberry和iOS设备。
安装
要在您的Symfony2项目中使用此包,请将以下内容添加到您的 composer.json
{
"require": {
// ...
"richsage/rms-push-notifications-bundle": "dev-master"
}
}
并在您的内核中启用它
<?php
// app/AppKernel.php
public function registerBundles()
{
$bundles = array(
// ...
new RMS\PushNotificationsBundle\RMSPushNotificationsBundle(),
);
}
注意:如果您仍在使用Symfony 2.0,请使用 symfony2.0
分支。
配置
可用的配置选项如下。请注意,只有当您为它们分别提供配置时,特定的服务才会可用。
rms_push_notifications:
android:
timeout: 5 # Seconds to wait for connection timeout, default is 5
c2dm:
username: <string_android_c2dm_username>
password: <string_android_c2dm_password>
source: <string_android_c2dm_source>
gcm:
api_key: <string_android_gcm_api_key> # This is titled "Server Key" when creating it
use_multi_curl: <boolean_android_gcm_use_multi_curl> # default is true
dry_run: <bool_use_gcm_dry_run>
ios:
timeout: 60 # Seconds to wait for connection timeout, default is 60
sandbox: <bool_use_apns_sandbox>
pem: <path_apns_certificate> # can be absolute or relative path (from app directory)
passphrase: <string_apns_certificate_passphrase>
mac:
timeout: 60 # Seconds to wait for connection timeout, default is 60
sandbox: <bool_use_apns_sandbox>
pem: <path_apns_certificate>
passphrase: <string_apns_certificate_passphrase>
blackberry:
timeout: 5 # Seconds to wait for connection timeout, default is 5
evaluation: <bool_bb_evaluation_mode>
app_id: <string_bb_app_id>
password: <string_bb_password>
windowsphone:
timeout: 5 # Seconds to wait for connection timeout, default is 5
注意:如果您正在使用Windows,您可能需要将Android GCM的use_multi_curl
标志设置为false,以便正确发送GCM消息。
超时默认值是引入此配置值之前默认值。
用法
以下是一个如何向iOS设备发送第一条消息的示例,我们假设您已正确设置了配置
use RMS\PushNotificationsBundle\Message\iOSMessage;
class PushDemoController extends Controller
{
public function pushAction()
{
$message = new iOSMessage();
$message->setMessage('Oh my! A push notification!');
$message->setDeviceIdentifier('test012fasdf482asdfd63f6d7bc6d4293aedd5fb448fe505eb4asdfef8595a7');
$this->container->get('rms_push_notifications')->send($message);
return new Response('Push notification send!');
}
}
发送方法将检测消息类型,如果您传递一个AndroidMessage
,它将自动通过C2DM/GCM服务器发送,同样适用于Mac和Blackberry。
Android消息
由于C2DM和GCM都仍然可用,AndroidMessage
类有一个小的标志来切换要发送到哪个服务。用法如下
use RMS\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建议您每天轮询此服务。
Windows Phone - Toast支持
该包对Windows Phone有测试支持,并支持Toast通知。使用WindowsphoneMessage
消息类进行相应发送。
感谢
首先,感谢所有为此包做出贡献的人!