c# - 发送 Voip Push 开发但不生产
问题描述
我正在使用JsSoft.Apple.Apns.Notification。当我做沙盒=真。它工作正常,但是当我更改为false时,没有收到通知。我也不会出现错误。请告诉我我错过了什么或做错了什么?Apple .p12 证书是为生产创建的。这是代码。或(https://github.com/Redth/APNS-Sharp)。
using System;
using System.Collections.Generic;
using System.Text;
using JdSoft.Apple.Apns.Notifications;
namespace JdSoft.Apple.Apns.Test
{
class Program
{
[STAThread]
static void Main(string[] args)
{
//Variables you may need to edit:
//---------------------------------
//True if you are using sandbox certificate, or false if using production
bool sandbox = false;
//Put your device token in here
string testDeviceToken = "7e6baf66c0a908f65e15b9575dd04c291021b7b77079624223b39cd053d38c26";
//Put your PKCS12 .p12 or .pfx filename here.
// Assumes it is in the same directory as your app
string p12File = @"C:\Users\Nouman\source\repos\AsteriskComunicationApi\AsteriskComunicationApi\p12File\VOIP_iOS_New.p12";
//This is the password that you protected your p12File
// If you did not use a password, set it as null or an empty string
string p12FilePassword = "12345678";
//Number of notifications to send
int count = 3;
//Number of milliseconds to wait in between sending notifications in the loop
// This is just to demonstrate that the APNS connection stays alive between messages
int sleepBetweenNotifications = 3000;
//Actual Code starts below:
//--------------------------------
string p12Filename = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, p12File);
NotificationService service = new NotificationService(sandbox, p12Filename, p12FilePassword, 1);
service.SendRetries = 5; //5 retries before generating notificationfailed event
service.ReconnectDelay = 5000; //5 seconds
service.Error += new NotificationService.OnError(service_Error);
service.NotificationTooLong += new NotificationService.OnNotificationTooLong(service_NotificationTooLong);
service.BadDeviceToken += new NotificationService.OnBadDeviceToken(service_BadDeviceToken);
service.NotificationFailed += new NotificationService.OnNotificationFailed(service_NotificationFailed);
service.NotificationSuccess += new NotificationService.OnNotificationSuccess(service_NotificationSuccess);
service.Connecting += new NotificationService.OnConnecting(service_Connecting);
service.Connected += new NotificationService.OnConnected(service_Connected);
service.Disconnected += new NotificationService.OnDisconnected(service_Disconnected);
//The notifications will be sent like this:
// Testing: 1...
// Testing: 2...
// Testing: 3...
// etc...
for (int i = 1; i <= count; i++)
{
//Create a new notification to send
Notification alertNotification = new Notification(testDeviceToken);
alertNotification.Payload.Alert.Body = string.Format("Testing {0}...", i);
alertNotification.Payload.Sound = "default";
alertNotification.Payload.Badge = i;
//Queue the notification to be sent
if (service.QueueNotification(alertNotification))
Console.WriteLine("Notification Queued!");
else
Console.WriteLine("Notification Failed to be Queued!");
//Sleep in between each message
if (i < count)
{
Console.WriteLine("Sleeping " + sleepBetweenNotifications + " milliseconds before next Notification...");
System.Threading.Thread.Sleep(sleepBetweenNotifications);
}
}
Console.WriteLine("Cleaning Up...");
//First, close the service.
//This ensures any queued notifications get sent befor the connections are closed
service.Close();
//Clean up
service.Dispose();
Console.WriteLine("Done!");
Console.WriteLine("Press enter to exit...");
Console.ReadLine();
}
}
}
解决方案
推荐阅读
- android - 嵌套的viewpager2
- python - 如何更新 LabelFrame 标题(Tkinter)
- .net-core - 在 .NET Core 中使用带有 COM 互操作的 .NET Framework DLL
- javascript - 使用Javascript更新json文件中的json键?
- javascript - 打开和关闭jQuery的类
- javascript - 异步 XMLHttpRequest 响应后,ng-grid 未绑定最新数据
- intellij-idea - 场景步骤(Given,When,Then)未显示在 IntelliJ 控制台中(Cucumber-Java with Junit)
- python - 无法在 Keras 功能 API 中将 FeatureColumn 与类别列一起使用
- kotlin - 什么时候应该使用加号、减号、时间函数而不是使用 Kotlin 中的运算符?
- python - dask 执行卡在 LocalCluster