pushsharp 2 在向苹果发送通知时引发异常 ios

pushsharp 2 fires an exception while sending notification to apple ios

我使用的是 PushSharp 2.0.4,它在向苹果发送通知时引发异常:

You have selected the Production server, yet your Certificate does not appear to be the Production certificate! Please check to ensure you have the correct certificate!

我注意到由于 Apple 证书政策的变化,我认为 pushsharp 2 中有一个硬编码值可以引用旧证书名称。

我现在不想转移到新的 pushsharp 3 版本,但我想在我的 pushsharp 2.0 代码中解决这个问题。

我认为更改应该在 ApplePushChannelSettings class:

private void CheckProductionCertificateMatching(bool production)
{
    if (this.Certificate == null)
    {
        throw new ArgumentNullException("You must provide a Certificate to connect to APNS with!");
    }
    string name = this.Certificate.IssuerName.Name;
    string name2 = this.Certificate.SubjectName.Name;
    if (!name.Contains("Apple"))
    {
        throw new ArgumentException("Your Certificate does not appear to be issued by Apple!  Please check to ensure you have the correct certificate!");
    }
    if (production && !name2.Contains("Apple Production IOS Push Services") && !name2.Contains("Apple Push Services"))
    {
        throw new ArgumentException("You have selected the Production server, yet your Certificate does not appear to be the Production certificate!  Please check to ensure you have the correct certificate!");
    }
    if (!production && !name2.Contains("Apple Development IOS Push Services") && !name2.Contains("Pass Type ID"))
    {
        throw new ArgumentException("You have selected the Development/Sandbox (Not production) server, yet your Certificate does not appear to be the Development/Sandbox certificate!  Please check to ensure you have the correct certificate!");
    }
}

这一行:

if (production && !name2.Contains("Apple Production IOS Push Services") && !name2.Contains("Apple Push Services"))
{
    throw new ArgumentException("You have selected the Production server, yet your Certificate does not appear to be the Production certificate!  Please check to ensure you have the correct certificate!");
}

但是我有一个问题想问以前遇到过这个问题的人,这是唯一应该做的改变吗?还有什么是正确的改变,或者具体来说,苹果使用的正确值是什么而不是这个?

更新: 我评论了 ApplePushChannelSettings.cs 中的一些行,这些行触发了异常,并且通知仅正确发送到 android 并且问题仍在 ios.

我找到了解决方案,它与 windows 上的证书配置有关。

首先你应该知道 apple 对其证书政策和行为做了一些小改动,所以你应该从 PushSharp 2 转换为 PushSharp 3,你会在我的回答中找到所有关于升级的信息:

此外,如果您有兴趣了解 apple 所做的更改以及它如何反映到 PushSharp 2,请检查: apple-push-services-created-instead-of-apple-production-ios-push-services

我还使用 mmc 将证书从用户帐户证书更改为本地计算机证书,并且我禁用了模拟身份验证和上面答案中的全部详细信息,但我不想再次重复。