我正试图用Ionic实现Push Notifications,我很困惑.到目前为止,我已经尝试了以下替代方案但没有成功:
离子推
似乎是最好的解决方案.它在浏览器中"模拟"通知,使其易于测试.有两个版本:
版本1.0:文档可在http://docs.ionic.io/v1.0/docs/push-overview上找到.该页面底部显示警告,说明要检查最新版本(2.0beta).如果我留在页面并尝试按照说明操作,一切似乎都运行正常,但如果我发送推送到https://push.ionic.io/api/v1/push没有消息到达.看看firebug我发现$ ionicPush正在查询2.0alpha API而不是查询1.0 API.
版本2.0:文档可在http://docs.ionic.io/docs/push-overview上找到.它与1.0非常相似,在浏览器,Android(开发和生产)和iOS开发环境中运行良好.但是,我无法获得有关IOS生产的消息(在将应用程序发布到商店之后).我努力寻找解决方案,但我找到了一些答案,说它是alpha,不应该使用.
因此,如果版本1.0不存在(它使用v2.0 API)并且v2.0是alpha并且不应该使用,我得出结论Ionic Push不能使用.
问题1:可以使用离子推送向iOS和Android发送通知吗?
问题2:使用2.0设置,我可以使用Apns PHP而不是Ionic Push发送消息吗?
Cordova Phonegap插件推送
这个插件是Ionic Push在我猜测的幕后使用的.但是,我无法弄清楚如何使用它.我发现的教程和文档已经过时,并引用了一个已弃用的版本(https://github.com/phonegap-build/PushPlugin.git).甚至ngCordova也引用了这个已弃用的版本(http://ngcordova.com/docs/plugins/pushNotifications/).ngCordova也建议使用Ionic Push.我找不到一个完整的例子,展示如何使用https://github.com/phonegap/phonegap-plugin-push with ionic.
问题3:如何设置Cordova Phonegap Plugin推离子?
我正在尝试从 apache Web 服务器托管的 javascript 客户端连接到 nodejs https 服务器,但收到一条错误消息:522 - Failed to load response data: No data found for resource with given indentifier。apache Web 服务器与节点服务器在同一域/服务器上运行,并且服务器由 Cloudflare 代理:
两种服务都在同一服务器/机器上运行。这就是我启动nodejs服务器的方式:
// Certificates are the same used by apache web server in Virtual Host
// and were got from Cloud Flare Panel > SSL/TLS > Origin Server
var options = {
key: fs.readFileSync('/etc/cloudflare/example.com.key'),
cert: fs.readFileSync('/etc/cloudflare/example.com.pem'),
};
var socket = …Run Code Online (Sandbox Code Playgroud) 我正在使用https://github.com/arnesson/cordova-plugin-firebase/在基于离子的应用上接收Google Firebase消息.
设置证书后,安装插件并设置Firebase帐户我能够通过Firebase控制台接收通知(在Android和ios设备上).
但是,当我通过Firebase API(https://firebase.google.com/docs/cloud-messaging/http-server-ref)发送邮件时,只有Android设备会收到通知.我正在使用以下代码:
$data = Array
(
[to] => <token>
[notification] => Array
(
[title] => My Title
[text] => Notification test
[sound] => default
[vibrate] => 1
[badge] => 0
)
)
$jsonData = json_encode($data);
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header = array(
'Content-Type: application/json',
"Authorization: key=".$gcmApiKey
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, true );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
Run Code Online (Sandbox Code Playgroud)
没有错误返回:
{"multicast_id":904572753471539870406,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1477063422322568734%3d5c78243d5c7824"}]}
Run Code Online (Sandbox Code Playgroud)
有什么不对?