【问题标题】:Push Notifications Not appears in IOS (Phonegap, C#)推送通知未出现在 IOS 中(Phonegap,C#)
【发布时间】:2015-01-29 21:33:04
【问题描述】:

我正在尝试向 APNS 发送推送通知,调试我的服务器进行身份验证并发送通知,但 iphone 上没有显示任何内容。

我正在使用

<gap:plugin name="com.phonegap.plugins.pushplugin" version="2.4.0" />

我可以使用以下代码捕获 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);
        }
    }

通知:

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);
}

}

以及带有令牌的代码:

function tokenHandler(result) {       
//alert('Token: ' + result);
//I send token to the server.
}

我从服务器到 APNS 的消息:

{"aps":{"alert":"Você tem um(a) Hidracor agendado(a)!","badge":1,"sound":"new.caf"},"lembrete": true}

我下载了 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

我使用这个文件 pushCert.p12 通过服务器使用 APNS 进行身份验证。

我用这个例子来连接APNS:

http://apns-c-sharp-net-vikram-jain.blogspot.com.br/

谁能帮帮我?

谢谢!

【问题讨论】:

    标签: c# ios iphone apple-push-notifications phonegap-plugins


    【解决方案1】:

    问题出在我的代码上,我举了一个例子,主要方法没有显着变化。然后我尝试了另一种解决方案,找到了 MoonAPNS 组件,实现了将使用 SSL3 身份验证的协议更改为 Default 并解决了我的问题。

    _apnsStream.AuthenticateAsClient(host, certificates, System.Security.Authentication.SslProtocols.Default, false);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      • 2013-06-11
      相关资源
      最近更新 更多