/// <summary> /// /// </summary> /// <param name="serverEnvironment"></param> /// <param name="certificatePath">path of .p12 file</param> /// <param name="certificatePass">.p12 file password.</param> public IOSPush(ApnsServerEnvironment serverEnvironment, string certificatePath, string certificatePass) { ServerEnvironment = serverEnvironment; host = serverEnvironment == ApnsServerEnvironment.Production ? APNS_PRODUCTION_HOST : APNS_SANDBOX_HOST; CertificatePath = certificatePath; CertificatePass = certificatePass; }
void Initialize(ApnsServerEnvironment serverEnvironment, X509Certificate2 certificate) { var production = serverEnvironment == ApnsServerEnvironment.Production; Host = production ? APNS_PRODUCTION_HOST : APNS_SANDBOX_HOST; FeedbackHost = production ? APNS_PRODUCTION_FEEDBACK_HOST : APNS_SANDBOX_FEEDBACK_HOST; Port = production ? APNS_PRODUCTION_PORT : APNS_SANDBOX_PORT; FeedbackPort = production ? APNS_PRODUCTION_FEEDBACK_PORT : APNS_SANDBOX_FEEDBACK_PORT; Certificate = certificate; MillisecondsToWaitBeforeMessageDeclaredSuccess = 3000; ConnectionTimeout = 10000; MaxConnectionAttempts = 3; FeedbackIntervalMinutes = 10; FeedbackTimeIsUTC = false; AdditionalCertificates = new List <X509Certificate2> (); AddLocalAndMachineCertificateStores = false; CheckIsApnsCertificate(); ValidateServerCertificate = false; KeepAlivePeriod = TimeSpan.FromMinutes(20); KeepAliveRetryPeriod = TimeSpan.FromSeconds(30); InternalBatchSize = 1000; InternalBatchingWaitPeriod = TimeSpan.FromMilliseconds(750); InternalBatchFailureRetryCount = 1; }
void Initialize (ApnsServerEnvironment serverEnvironment, X509Certificate2 certificate) { var production = serverEnvironment == ApnsServerEnvironment.Production; Host = production ? APNS_PRODUCTION_HOST : APNS_SANDBOX_HOST; Port = production ? APNS_PRODUCTION_PORT : APNS_SANDBOX_PORT; Certificate = certificate; MillisecondsToWaitBeforeMessageDeclaredSuccess = 3000; ConnectionTimeout = 10000; MaxConnectionAttempts = 3; FeedbackIntervalMinutes = 10; FeedbackTimeIsUTC = false; AdditionalCertificates = new List<X509Certificate2> (); AddLocalAndMachineCertificateStores = false; CheckIsApnsCertificate (); ValidateServerCertificate = false; KeepAlivePeriod = TimeSpan.FromMinutes (20); KeepAliveRetryPeriod = TimeSpan.FromSeconds (30); InternalBatchSize = 1000; InternalBatchingWaitPeriod = TimeSpan.FromMilliseconds (750); InternalBatchFailureRetryCount = 1; }
public ApplePusher() { CertPath = Configuration.GetSection("certpath").Value; CertPassWord = Configuration.GetSection("certpassword").Value; DeviceTokenLength = Configuration.GetValue("devicetokenlength", 64); apnsServerEnvironment = Configuration.GetValue("apnsserver", ApnsServerEnvironment.Production); config = new ApnsConfiguration(apnsServerEnvironment, CertPath, CertPassWord); apnsBroker = new ApnsServiceBroker(config); apnsBroker.OnNotificationFailed += (notification, aggregateEx) => { aggregateEx.Handle(ex => { // See what kind of exception it was to further diagnose 判断例外,进行诊断 if (ex is ApnsNotificationException notificationException) { // Deal with the failed notification 处理失败的通知 var apnsNotification = notificationException.Notification; var statusCode = notificationException.ErrorStatusCode; Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}"); OnSendFail?.Invoke(notificationException); } else { // Inner exception might hold more useful information like an ApnsConnectionException 内部异常 Console.WriteLine($"Apple Notification Failed for some unknown reason : {ex.InnerException}"); OnSendInnerFail?.Invoke(ex); } // Mark it as handled 标记为处理 return(true); }); }; apnsBroker.OnNotificationSucceeded += (notification) => { Console.WriteLine("Apple Notification Sent ! " + notification.DeviceToken); OnSendSuccess?.Invoke(notification); }; }
public ApnsConfiguration (ApnsServerEnvironment serverEnvironment, X509Certificate2 certificate, bool validateIsApnsCertificate) { Initialize (serverEnvironment, certificate, validateIsApnsCertificate); }
public ApnsConfiguration (ApnsServerEnvironment serverEnvironment, X509Certificate2 certificate) { Initialize (serverEnvironment, certificate, true); }
public ApnsConfiguration (ApnsServerEnvironment serverEnvironment, byte[] certificateData, string certificateFilePwd) : this (serverEnvironment, new X509Certificate2 (certificateData, certificateFilePwd, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable)) { }
public ApnsConfiguration (ApnsServerEnvironment serverEnvironment, string certificateFile, string certificateFilePwd) : this (serverEnvironment, System.IO.File.ReadAllBytes (certificateFile), certificateFilePwd) { }
public ApnsConfiguration(ApnsServerEnvironment serverEnvironment, X509Certificate2 certificate) { Initialize(serverEnvironment, certificate); }
public ApnsConfiguration(ApnsServerEnvironment serverEnvironment, byte[] certificateData, string certificateFilePwd) : this(serverEnvironment, new X509Certificate2(certificateData, certificateFilePwd, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable)) { }
public ApnsConfiguration(ApnsServerEnvironment serverEnvironment, string certificateFile, string certificateFilePwd) : this(serverEnvironment, System.IO.File.ReadAllBytes(certificateFile), certificateFilePwd) { }