I'm trying send push notifications to APNS, debugging my server authenticates and sends the notification, but nothing appears on the iphone.
我正在尝试向APNS发送推送通知,调试我的服务器进行身份验证并发送通知,但iphone上没有任何内容。
I'm using
我在用着
<gap:plugin name="com.phonegap.plugins.pushplugin" version="2.4.0" />
I can catch the deviceToken to send the pushs with the following code:
我可以使用以下代码捕获deviceToken以发送推送:
if (device.platform == "iOS"){
try
{
var pushNotification = window.plugins.pushNotification;
if (pushNotification != undefined){
pushNotification.register(
tokenHandler,
errorHandler, {
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
}
catch(e)
{
alert('erro ao registrar ios: ' + e.message + ', stack: ' + e.stack);
}
}
OnNotification:
OnNotification:
function onNotificationAPN(event) {
alert('notificationapn: ' + JSON.stringify(event));
try
{
if (event.alert)
{
if (event.foreground == 1){
if (event.alertaID != undefined){
navigator.notification.alert(
event.alertaCorpo,
function(){ },
'Mensagem de Incentivo',
'Ok'
);
}
else if (event.lembrete != undefined){
navigator.notification.alert(
event.alert,
function(){ },
'Lembrete',
'Ok'
);
}
}
else
{
if (event.alertaID != undefined){
mostraPopupAguarde();
var mensagensIncentivo = new Array();
var alerta = new Object();
alerta.ID = event.alertaID;
alerta.UrlImagem = event.alertaUrlImagem;
alerta.Nome = event.alertaNome;
alerta.Corpo = event.alertaCorpo;
mensagensIncentivo.push(alerta);
window.localStorage.setItem('mensagensIncentivo', JSON.stringify(mensagensIncentivo));
carregaMensagemIncentivo(alerta.ID);
ocultaPopupAguarde();
}
else if (event.lembrete != undefined){
navigator.notification.alert(
event.alert,
function(){ },
'Lembrete',
'Ok'
);
}
}
}
if ( event.sound )
{
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
catch(e)
{
alert('erro ao registrar ios: ' + e.message + ', stack: ' + e.stack);
}
}
}
and the code with token:
以及带令牌的代码:
function tokenHandler(result) {
//alert('Token: ' + result);
//I send token to the server.
}
My message from server to APNS:
我从服务器到APNS的消息:
{"aps":{"alert":"Você tem um(a) Hidracor agendado(a)!","badge":1,"sound":"new.caf"},"lembrete": true}
I downloaded the aps_development.cer and executed the following commands with openssl:
我下载了aps_development.cer并使用openssl执行了以下命令:
openssl x509 -in "aps_development.cer" -inform DER -out "path_to_an_output_Cert.pem" -outform PEM
openssl pkcs12 -export -inkey ios.key -in aps_development.pem -out aps_development.p12
openssl pkcs12 -nocerts -in "aps_development.p12" -out "path_to_an_output_Key.pem" -passin pass:mykey -passout pass:mykey
openssl pkcs12 -export -inkey "path_to_an_output_Key.pem" -in "path_to_an_output_Cert.pem" -out "pushCert.p12" -passin pass:mykey -passout pass:mykey
I use this file pushCert.p12 to authenticate via server with APNS.
我使用此文件pushCert.p12通过服务器与APNS进行身份验证。
I use this example to connect with the APNS:
我用这个例子来连接APNS:
http://apns-c-sharp-net-vikram-jain.blogspot.com.br/
http://apns-c-sharp-net-vikram-jain.blogspot.com.br/
Can anyone help me?
谁能帮我?
Thanks!
谢谢!
1 个解决方案
#1
0
The problem was with my code, which I cited as an example, there was no significant change of the main methods. Then I tried another solution and found the MoonAPNS component, realized a change in the protocol that was using the SSL3 authentication to Default and that solved my problem.
问题在于我的代码,我举例说,主要方法没有重大变化。然后我尝试了另一个解决方案并找到了MoonAPNS组件,实现了对使用SSL3身份验证到Default的协议的更改,这解决了我的问题。
_apnsStream.AuthenticateAsClient(host, certificates, System.Security.Authentication.SslProtocols.Default, false);
#1
0
The problem was with my code, which I cited as an example, there was no significant change of the main methods. Then I tried another solution and found the MoonAPNS component, realized a change in the protocol that was using the SSL3 authentication to Default and that solved my problem.
问题在于我的代码,我举例说,主要方法没有重大变化。然后我尝试了另一个解决方案并找到了MoonAPNS组件,实现了对使用SSL3身份验证到Default的协议的更改,这解决了我的问题。
_apnsStream.AuthenticateAsClient(host, certificates, System.Security.Authentication.SslProtocols.Default, false);