public ApnsPusher(string keyId, string teamId, string bundleAppId, string certificatePath, string certificatePassword, ApnsEnvironment environment, int port = 443) { Environment = environment; KeyId = keyId; TeamId = teamId; BundleAppId = bundleAppId; switch (Environment) { case ApnsEnvironment.Production: Host = $"{ProductionUrl}:{port}/3/device/"; break; case ApnsEnvironment.Sandbox: Host = $"{SandboxUrl}:{port}/3/device/"; break; } var certificate = new X509Certificate2(certificatePath, certificatePassword); PrivateKey = certificate.GetECDsaPrivateKey(); if (PrivateKey == null) { throw new ArgumentException("Certificate does not contains ECDsa private key."); } _jsonSettings = new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }; }
public ApnsPusher(ILogger <ApnsPusher> logger, string keyId, string teamId, string bundleAppId, string certificatePath, string certificatePassword, ApnsEnvironment environment, int port = 443) { _logger = logger; Environment = environment; KeyId = keyId; TeamId = teamId; BundleAppId = bundleAppId; switch (Environment) { case ApnsEnvironment.Production: Host = $"{ProductionUrl}:{port}/3/device/"; break; case ApnsEnvironment.Sandbox: Host = $"{SandboxUrl}:{port}/3/device/"; break; } try { var certificate = new X509Certificate2(certificatePath, certificatePassword); PrivateKey = certificate.GetECDsaPrivateKey(); } catch (Exception e) { _logger.LogCritical(e, $"Failed to load certeficate at {certificatePath} with password {certificatePassword}\n"); throw; } if (PrivateKey == null) { throw new ArgumentException("Certificate does not contains ECDsa private key."); } _jsonSettings = new JsonSerializerSettings { Formatting = Formatting.None, NullValueHandling = NullValueHandling.Ignore }; }