APNS输入字符串的格式不正确。(APNS Input string was not in a correct format. Disconnected)

编程入门 行业动态 更新时间:2024-10-28 02:24:01
APNS输入字符串的格式不正确。(APNS Input string was not in a correct format. Disconnected)

我正在尝试设置苹果推送通知,我正在为服务器编写自己的代码,据我所知,我已经正确设置了应用程序。 如何从日志中恢复以下错误:

收到有效负载队列。 连接到苹果服务器。 创建SSL连接。 Conected。 为“Token在此处生成的有效负载我删除它:{”aps“:{”alert“:”test“,”badge“:1,”sound“:”default“}}通知已成功发送到APNS服务器以获取设备Toekn: “Token在这里我删除了它”在读取Apple响应时出现错误令牌“令牌在这里我删除了它” - 输入字符串的格式不正确。断开连接

这是我的代码。

var push = new PushNotification(true, @"C:\wwwroot\UltraNet\PushService\bin\Debug\206dist.p12", "ultrait"); var payload = new NotificationPayload("devicetoken here ive deleted it", "test", 1, "default"); var p = new List<NotificationPayload> { payload }; var result = push.SendToApple(p); Console.ReadLine();

我确保证书等设置正确。

我现在正在测试它作为一个adhoc应用程序,因为新版本需要很长时间才能上线。

我真的不知道我哪里出错了,如果有人可以帮助它会很棒,谢谢你。

我也不知道我需要对我创建的PEM文件做些什么。

编辑* * *

我有正确的令牌,这是我收到的另一个错误

对于df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053产生有效载荷:{ “APS”:{ “警告”: “测试”, “徽章”:1, “声音”: “默认”}}通知成功发送到APNS服务器设备Toekn:df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053断开。 读取令牌的Apple响应时出错df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053 - 安全句柄已关闭

I am trying to set up apple push notifications, i am writing my own code for the server and as far as i know i have set up the app correctly. How ever i keep getting the following error come back from the log:

Payload queue received. Connecting to apple server. Creating SSL connection. Conected. Payload generated for "Token goes here i deleted it : {"aps":{"alert":"test","badge":1,"sound":"default"}} Notification successfully sent to APNS server for Device Toekn : "Token here I've deleted it" An error occurred while reading Apple response for token "Token here I've deleted it" - Input string was not in a correct format. Disconnected

This is my code.

var push = new PushNotification(true, @"C:\wwwroot\UltraNet\PushService\bin\Debug\206dist.p12", "ultrait"); var payload = new NotificationPayload("devicetoken here ive deleted it", "test", 1, "default"); var p = new List<NotificationPayload> { payload }; var result = push.SendToApple(p); Console.ReadLine();

I have made sure that the certificates etc are set up correctly.

I am testing it as a adhoc app at the moment because it takes so long for a new version to be able to go live.

I really don't know where I'm going wrong if any one could help it would be brilliant thank you.

I also don't know what i need to do with the PEM files that i have created.

Edit***

I have the correct token this is another error that i receive

Payload generated for df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053 : {"aps":{"alert":"test","badge":1,"sound":"default"}} Notification successfully sent to APNS server for Device Toekn : df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053 Disconnected. An error occurred while reading Apple response for token df99286a1cb993cecba86b2e21f3fc4c04d214fcf7e0cf35a668fc822bdaa053 - Safe handle has been closed

最满意答案

根据ReadResponse的代码(见下文), Input string was not in a correct format错误消息是指从Apple收到的响应,而不是您发送的通知。 代码无法正确读取Apple的错误响应。

如果它成功读取了响应,您就会知道确切的故障是什么以及哪个消息失败了。 由于您没有错误响应,因此可以安全地假设问题是您的设备令牌。 这是最常见的失败。 如果您可以隔离发生错误的设备令牌,则只需从数据库中删除该令牌即可。 当您尝试在推送到生产环境时使用沙箱令牌或反之亦然时,通常会发生无效的设备令牌错误。

private void ReadResponse(IAsyncResult ar) { if (!_conected) return; string payLoadId = ""; int payLoadIndex = 0; try { var info = ar.AsyncState as MyAsyncInfo; info.MyStream.ReadTimeout = 100; if (_apnsStream.CanRead) { var command = Convert.ToInt16(info.ByteArray[0]); var status = Convert.ToInt16(info.ByteArray[1]); var ID = new byte[4]; Array.Copy(info.ByteArray, 2, ID, 0, 4); payLoadId = Encoding.Default.GetString(ID); payLoadIndex = ((int.Parse(payLoadId)) - 1000); Logger.Error("Apple rejected palyload for device token : " + _notifications[payLoadIndex].DeviceToken); Logger.Error("Apple Error code : " + _errorList[status]); Logger.Error("Connection terminated by Apple."); _rejected.Add(_notifications[payLoadIndex].DeviceToken); _conected = false; } } catch (Exception ex) { Logger.Error("An error occurred while reading Apple response for token {0} - {1}", _notifications[payLoadIndex].DeviceToken, ex.Message); } }

It was all to do with my certificates. Because i hadn't turnt my combined PEM certificate back to a p12 file.

更多推荐

本文发布于:2023-07-07 04:21:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058922.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   不正确   格式   APNS   Input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!