我尝试使用apns-csharp库从.NET发送推送通知,我在Apple Provision Portal上创建了证书,下载并转换为p12格式,当我尝试使用代码加载它时:
private ActionResult SendAlertPushNotification(string appId, string notificationContent, bool useSandBox)
{
NotificationService notificationService = new NotificationService(useSandBox,ApplicationsRepository.GetAPNSCertificateForApplication(appId,useSandBox),"123",1);
notificationService.ReconnectDelay = 2000;
notificationService.Error += new NotificationService.OnError(service_Error);
notificationService.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
notificationService.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
notificationService.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
notificationService.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
notificationService.Connecting += new NotificationService.OnConnecting(service_Connecting);
notificationService.Connected += new NotificationService.OnConnected(service_Connected);
notificationService.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
var devices = ApplicationsRepository.GetPushClientDevicesID(appId);
foreach (var token in devices)
{
var notification = new Notification(token);
notification.Payload.Alert.Body = notificationContent;
notification.Payload.Sound = "default";
notification.Payload.Badge = 1;
//Queue the notification to be sent
if (notificationService.QueueNotification(notification))
Debug.WriteLine("Notification Queued!");
else
Debug.WriteLine("Notification Failed to be Queued!");
}
notificationService.Close();
ViewData["app"] = ApplicationsRepository.GetApplicationByAppId(appId);
ViewData["count"] = devices.Count;
return View("SendSuccess");
}
尝试加载证书时收到内部错误。如果我使用原始证书,如果.cer格式,我没有收到任何例外,但没有实际发送给APNS服务器。有人遇到过这个问题吗?
答案 0 :(得分:2)
确保您已导出正确的证书。我最近遇到了类似的问题,却发现我输错了。
OSX Keychain 你创建了之后 适当的推送通知 iPhone开发人员证书 您应该拥有的程序门户 下载了一个名为的文件 apn_developer_identity.cer。如果你 你还没有这样做过 打开/导入此文件到Keychain, 进入你的登录部分。
最后,如果您将Keychain过滤到 显示您的登录容器 证书,你应该看到你的 证书已列出。展开 证书,应该有一把钥匙 在它下面/附着它。
右键单击或Ctrl +单击 适当的证书并选择 出口。钥匙扣会问你 选择要导出的密码。挑 一个并记住它。你应该结束 使用.p12文件。你需要这个 文件和您选择的密码 使用通知和反馈 这里的图书馆。
我现在确定你已经解决了这种方式或者另一种方式,但是刚刚经历过我的自我,我认为放下我的经验可能会很好。