29

我的应用程序刚刚准备好在 App Store 上销售,但我的生产设备(已从 App Store 安装应用程序的设备)都没有收到推送通知。当我尝试向生产设备发送推送通知时,我收到此错误:

"The credentials supplied to the package were not recognized" 
(System.ComponentModel.Win32Exception)

此异常在内部抛出并陷入无限循环:

在此处输入图像描述

它在ApplePushChannel.cs文件的第 539 行抛出:

    try
{
    stream.AuthenticateAsClient(this.appleSettings.Host, this.certificates, 
        System.Security.Authentication.SslProtocols.Ssl3, false);
    //stream.AuthenticateAsClient(this.appleSettings.Host);
}
catch (System.Security.Authentication.AuthenticationException ex)
{
    throw new ConnectionFailureException("SSL Stream Failed to Authenticate as Client", ex);
}

这是 Visual Studio 输出中应用程序的输出:

...
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
A first chance exception of type 'System.ObjectDisposedException' occurred in System.dll
A first chance exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
...(it keeps getting thrown until I stop it manually)

以下是我尝试过的事情:

  • 仔细检查我正在尝试的设备 ID 是否已使用生产设备令牌注册。
  • 吊销并重新生成 APNS 生产证书,将其与私钥一起导出到新.p12文件,然后使用新证书再次尝试。(我在开发推送通知方面遇到了同样的问题,这解决了我的问题)
  • 将 SSL 协议从 更改Ssl3Tls. (前几天协议版本有问题,暂时解决了一个问题。应该不需要这个,但我得到的错误与我之前得到的错误相同)
  • 检查我实际上是在尝试使用生产证书而不是开发服务器/证书连接到生产服务器。
  • 检查我是否可以直接访问 APNS 服务器(我的 ASP.NET 应用程序位于我的 Mac 上的 Parallels VM Windows 8.1 中,这是我的 Mac 的输出,只是为了避免混淆:

(终端输出) 编辑:我在 ping 沙箱服务器,我已经 ping 生产服务器,我验证我也可以连接到它,所以这不是问题。

can$ sudo nmap -p 2195 gateway.sandbox.push.apple.com
Starting Nmap 6.40-2 ( http://nmap.org ) at 2014-04-28 00:06 EEST
Nmap scan report for gateway.sandbox.push.apple.com (17.149.34.189)
Host is up (0.49s latency).
Other addresses for gateway.sandbox.push.apple.com (not scanned): 17.149.34.187 17.149.34.188
PORT     STATE SERVICE
2195/tcp open  unknown

为什么 PushSharp 不与 APNS 服务器协商?

4

6 回答 6

81

我解决了这个问题。我再次撤销并重新生成了证书,这次我只导出了私钥(没有证书)。在钥匙串访问中,我导出为.p12并使用了新文件,它工作正常。.p12出于某种原因,当文件中同时存在证书和私钥时,PushSharp 不能很好地使用。

于 2014-04-28T11:50:57.640 回答
3

“无法识别提供给包的凭据”异常通常表示运行代码的用户没有足够的权限。

如果您从 Azure Web 应用程序或 Web 作业发送推送通知,请不要从文件或 base64 编码字符串加载 APNS 证书。转至 Azure 门户并将证书添加到网站。注意指纹。

Azure 门户中的证书

接下来添加 WEBSITE_LOAD_CERTIFICATES 设置并将其设置为*(星号)。

现在可以从 C# 代码中使用 APNS 证书:

string thumbprint = "YOUR THUMBPRINT";
var store = new X509Store(StoreName.My, StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
var certificate = store.Certificates.Find(
    X509FindType.FindByThumbprint, thumbprint, validOnly: false)
    .Cast<X509Certificate2>().SingleOrDefault();
var apnsConfig = new ApnsConfiguration(
    ApnsConfiguration.ApnsServerEnvironment.Production, certificate);

参考

于 2016-07-19T01:31:24.913 回答
1

使用 Windows 证书存储时(恕我直言,这是在生产服务器上管理证书的最简单方法),请务必在私钥上设置正确的权限。

于 2016-01-21T15:03:34.037 回答
1

没有一个答案对我有用。最后,我最终将证书和私钥导入 Windows 证书存储区,然后导出为.pfx.

于 2017-02-15T11:07:54.517 回答
1

我一次又一次地测试它。

p12文件转换为pem格式,它将适用于 IIS 受限用户,也许适用于 Azure....

于 2017-02-22T10:08:10.530 回答
0

我收到了同样的异常,在我的情况下,我必须为我的 IOS 推送服务证书添加权限。

右键单击 mmc 中的证书 -> 所有任务 -> 管理私钥...我添加了 NETWORK SERVICE 因为我的 Web 应用程序的 iis 应用程序池使用了该帐户。

有关更多详细信息,请参阅:http: //blog.falafel.com/apple-push-notifications-certificates-and-iis/

于 2016-01-25T15:33:17.483 回答