我一直在尝试使用 MoonAPNS 库找出我的 Apple 应用程序的有效令牌列表。使用 GetFeedBack() 时,收到的令牌数在几分钟后会发生巨大变化。第一次尝试它大约是 8000。然后它是 0 在第三次尝试它是 1 再次它是 0。
我正在使用有效的生产证书。& 已成功将使用相同证书的通知推送到采样设备。
我不了解代码的逻辑以及它提供接收令牌的基础。从 Moon APNS 下载的代码如下。
public List<Feedback> GetFeedBack()
{
try
{
var feedbacks = new List<Feedback>();
Logger.Info("Connecting to feedback service.");
if (!_conected)
Connect(_feedbackHost, FeedbackPort, _certificates);
if (_conected)
{
//Set up
byte[] buffer = new byte[38];
int recd = 0;
DateTime minTimestamp = DateTime.Now.AddYears(-1);
//Get the first feedback
recd = _apnsStream.Read(buffer, 0, buffer.Length);
Logger.Info("Feedback response received.");
if (recd == 0)
Logger.Info("Feedback response is empty.");
//Continue while we have results and are not disposing
while (recd > 0)
{
Logger.Info("processing feedback response");
var fb = new Feedback();
//Get our seconds since 1970 ?
byte[] bSeconds = new byte[4];
byte[] bDeviceToken = new byte[32];
Array.Copy(buffer, 0, bSeconds, 0, 4);
//Check endianness
if (BitConverter.IsLittleEndian)
Array.Reverse(bSeconds);
int tSeconds = BitConverter.ToInt32(bSeconds, 0);
//Add seconds since 1970 to that date, in UTC and then get it locally
fb.Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(tSeconds).ToLocalTime();
//Now copy out the device token
Array.Copy(buffer, 6, bDeviceToken, 0, 32);
fb.DeviceToken = BitConverter.ToString(bDeviceToken).Replace("-", "").ToLower().Trim();
//Make sure we have a good feedback tuple
if (fb.DeviceToken.Length == 64 && fb.Timestamp > minTimestamp)
{
//Raise event
//this.Feedback(this, fb);
feedbacks.Add(fb);
}
//Clear our array to reuse it
Array.Clear(buffer, 0, buffer.Length);
//Read the next feedback
recd = _apnsStream.Read(buffer, 0, buffer.Length);
}
//clode the connection here !
Disconnect();
if (feedbacks.Count > 0)
Logger.Info("Total {0} feedbacks received.", feedbacks.Count);
return feedbacks;
}
}
catch (Exception ex)
{
Logger.Error("Error occurred on receiving feed back. - " + ex.Message);
return null;
}
return null;
}
}