pushsharp 2在向apple ios

时间:2016-02-24 12:47:45

标签: c# ios pushsharp

我使用了PushSharp 2.0.4,并在向apple发送通知时触发异常:

  

您已选择生产服务器,但您的证书似乎不是生产证书!请检查以确保您拥有正确的证书!

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

我不想转移到新的pushsharp 3版本,但我想在我的pushsharp 2.0代码中修复此问题。

我认为更改应该在ApplePushChannelSettings类中:

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

但我之前有任何一个人面临这个问题的问题,这是唯一应该做的改变,还有正确的改变是什么,或具体是什么是苹果使用的正确值而不是这个? / p>

更新: 我评论了ApplePushChannelSettings.cs中的一些行,触发异常的行,以及仅向android发送的通知,问题仍在ios中。

1 个答案:

答案 0 :(得分:0)

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

首先,你应该知道苹果对它的证书政策和行为进行了微小的改动,所以你应该从PushSharp 2 tp PushSharp 3进行转换,你会在我的回答中找到所有关于升级的内容: / p>

production-certificate-error-in-push-notification-pushsharp

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

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