ciricihq / 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 not auto-updated.
Last update: 2024-09-15 02:12:58 UTC
README
一个允许向移动设备发送推送通知的扩展包。目前支持Android(C2DM、GCM)、Blackberry和iOS设备。
安装
要在您的Symfony2项目中使用此扩展包,请将以下内容添加到您的 composer.json
{
"require": {
// ...
"richsage/rms-push-notifications-bundle": "dev-master"
}
}
并在您的kernel中启用它
<?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!');
}
}
send方法将检测消息类型,如果您传递给它一个AndroidMessage
,它将自动通过C2DM/GCM服务器发送,对Mac和Blackberry也是如此。
Android消息
由于C2DM和GCM仍然可用,AndroidMessage
类上有一个小的标志可以切换要发送到哪个服务。如下使用
use RMS\PushNotificationsBundle\Message\AndroidMessage;
$message = new AndroidMessage();
$message->setGCM(true);
以发送GCM消息而不是C2DM。
iOS反馈服务
苹果推送通知服务还公开了一个反馈服务,您可以从中获取有关失败推送通知的信息 - 有关更多详细信息,请参阅此处。
此服务在扩展包中可用。以下代码演示了如何从服务中检索数据
$feedbackService = $container->get("rms_push_notifications.ios.feedback");
$uuids = $feedbackService->getDeviceUUIDs();
在这里,$uuids
包含一个包含时间戳、令牌长度和设备UUID的 Feedback 对象数组。
苹果建议您每天轮询此服务。
Windows Phone - Toast支持
此扩展包对Windows Phone提供beta支持,并支持Toast通知。使用WindowsphoneMessage
消息类发送相应的消息。
感谢
首先,感谢所有为这个扩展包做出贡献的人!