当我们以错误的方式进行操作时,代码会显示错误消息,但如果正确使用它,则不会发生任何事情

时间:2019-07-17 05:01:46

标签: c# apple-push-notifications

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;
}

0 个答案:

没有答案