push.StopAllServices()
从不会在调用后返回结果。如果我们传递了一些无效数据,例如密码错误或证书过期,则可以正常工作并给出预期的结果
var 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;
string PEMFILE = ConfigurationManager.AppSettings["PEMFILE"];
bool isProduction = Convert.ToBoolean(Convert.ToInt32(ConfigurationManager.AppSettings["IsProduction"]));
string password = ConfigurationManager.AppSettings["Password"];
string pempFile = System.Web.Hosting.HostingEnvironment.MapPath(PEMFILE);
var appleCert = File.ReadAllBytes(pempFile); //File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pempFile));
push.RegisterAppleService(new ApplePushChannelSettings(isProduction, appleCert, password)); //Extension method
foreach(var iosDevice in deviceIds)
{
push.QueueNotification(new AppleNotification()
.ForDeviceToken(iosDevice.DeviceId)
.WithAlert(message)
.WithBadge(1)
.WithContentAvailable(1)
.WithSound("sound.caf"));
}
try
{
push.StopAllServices();
}
catch (Exception ex)
{
var amessage = ex.InnerException.Message;
}