3

我有一个 WCF 服务,可以使用 APNS 向 IOS 设备发送推送通知。我将以下代码与 PushSharp 一起使用。

我在“RegisterAppleService”步骤中遇到错误。错误解释为: “CryptographicException was unhandled by user code The parameter is wrong.”

    private static PushBroker push;

    public string SendNotification()
    {
        push = new PushBroker();
        push.OnNotificationSent += NotificationSent;
        push.OnChannelException += ChannelException;
        push.OnServiceException += ServiceException;
        push.OnNotificationFailed += NotificationFailed;
        push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
        push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
        push.OnChannelCreated += ChannelCreated;
        push.OnChannelDestroyed += ChannelDestroyed;

        var appleCert = File.ReadAllBytes("CERT_FILE_NAME.p12");
        push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "PASSWORD"));

        string devToken = "DEVICE_TOKEN";
        push.QueueNotification(new AppleNotification()
                                   .ForDeviceToken(devToken)
                                   .WithAlert("Hello World!")
                                   .WithBadge(7)
                                   .WithSound("sound.caf"));

我找不到问题的原因。我该如何处理该异常?谢谢你。

4

1 回答 1

3

I suspect that you are using only the key generated with the signing request and not the certificate itself.

https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-Apple-Push-Notifications-using-PushSharp

The steps are provided here, on step 18 be sure that you are exporting your certificate that is associated with the key and not just the key itself.

Also be sure that you are using development/sandbox ssl certificate for the development phase.

于 2014-05-12T20:56:53.900 回答