c# - PushSharp 异常 : The credentials supplied to the package were not recognized

标签 c# ios push-notification pushsharp

我在使用 Pushsharp 的 IOS 推送通知中遇到以下异常。我搜索了很多文章,但不清楚如何继续。Andoid 工作正常,只是这个 IOS 的问题。

异常:

System.ComponentModel.Win32Exception (0x80004005): The credentials supplied to the package were not recognized
   at System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface SecModule, String package, CredentialUse intent, SecureCredential scc)
   at System.Net.Security.SecureChannel.AcquireCredentialsHandle(CredentialUse credUsage, SecureCredential& secureCredential)
   at System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]& thumbPrint)
   at System.Net.Security.SecureChannel.GenerateToken(Byte[] input, Int32 offset, Int32 count, Byte[]& output)
   at System.Net.Security.SecureChannel.NextMessage(Byte[] incoming, Int32 offset, Int32 count)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   at System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
   at PushSharp.Apple.FeedbackService.Run(ApplePushChannelSettings settings, CancellationToken cancelToken)
   at PushSharp.Apple.ApplePushService.<ApplePushService>c__AnonStorey0.<>m__1(Object state)}

我的代码:

    PushBroker 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(@"C:\Data\abc\Cert\CCDevelopment.p12"); 
    push.RegisterAppleService(new ApplePushChannelSettings(false, appleCert, "password")); //Extension method
   push.QueueNotification(new AppleNotification()                                                                      .ForDeviceToken("tokenId") //dev
                                 .WithAlert(msg) //load
                                 .WithBadge(1));  //

最佳答案

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

推荐链接 PushSharp APNS production: The credentials supplied to the package were not recognized (development works fine though)

关于c# - PushSharp 异常 : The credentials supplied to the package were not recognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31010955/

相关文章:

c# - 免费提供的 Web 服务/API

c# - 具有 ASP.NET 标识的 Entity Framework Multi-Tenancy

ios - Xcode swift : Login/Signup Page not displaying first due to slideoutmenu

iphone - 调用 setEditing 时自定义 UITableViewCell 调整大小标签

android - 安卓开发App Key和App Secret

http - Websocket、Server Sent Events (SSE) 和 HTTP2 的 Server Pushing 有什么区别?

Android推送通知Urban AirShip错误: invalid authorization on platform GCM

C# DataGridView.Rows.ToString() 方法

c# - 如何指示 DbConnection.GetSchema 返回其值的顺序?

ios - 在继续 swift 之前等待后台请求在 Alamofire 中完成并加载数组