Example #1
0
        static void Main(string[] args)
        {
            var keyId       = "";
            var teamId      = "";
            var bundleAppId = "";
            var keyPath     = "";
            var keyPassword = "";

            var deviceToken = "";

            var pusher = new ApnsPusher(keyId, teamId, bundleAppId, keyPath, keyPassword, ApnsEnvironment.Production);

            var notification = new ExtendedApnsNotification
            {
                Payload = new ApnsPayload
                {
                    Alert = new ApnsNotificationAlert
                    {
                        TitleLocalizationKey = "NotificationsService.NewMessage.Title",
                        BodyLocalizationKey  = "NotificationsService.NewMessage.BodySingle"
                    },
                    Badge          = 7,
                    MutableContent = 1
                },
                TxnId = ""
            };

            pusher.OnNotificationSuccess += OnNotificationSuccess;
            pusher.OnNotificationFailed  += OnNotificationFailed;

            Console.WriteLine("Sending notification...");
            pusher.SendNotificationAsync(notification, deviceToken);
        }
        public ApplePusher(ILogger <ApplePusher> logger, ILogger <ApnsPusher> internalLogger, IConfiguration configuration)
        {
            _logger        = logger;
            _configuration = configuration;

            Func <string, IConfiguration, string> getRequiredParam = (key, config) =>
            {
                var value = config[key];
                if (value == null)
                {
                    throw new ArgumentException($"Can't get {key}");
                }

                return(value);
            };

            _contents = LoadPayloadContent(_configuration);

            var keyId       = getRequiredParam("ApplePusher:Keys:keyId", configuration);
            var teamId      = getRequiredParam("ApplePusher:Keys:teamId", configuration);
            var bundleAppId = getRequiredParam("ApplePusher:Keys:bundleAppId", configuration);
            var pfxPath     = Utilities.HandleUnixHomeDirectory(getRequiredParam("ApplePusher:Keys:pfxPath", configuration));
            var pfxPassword = getRequiredParam("ApplePusher:Keys:pfxPassword", configuration);


            pusher = new ApnsPusher(internalLogger, keyId, teamId, bundleAppId, pfxPath, pfxPassword, ApnsEnvironment.Production);
            pusher.OnNotificationSuccess += Pusher_OnNotificationSuccess;
            pusher.OnNotificationFailed  += Pusher_OnNotificationFailed;
        }
        static void Main(string[] args)
        {
            var keyId       = "";
            var teamId      = "";
            var bundleAppId = "";
            var keyPath     = "";
            var keyPassword = "";

            var deviceToken = "";

            NLog.LogManager.LoadConfiguration("NLog.config");
            var loggerFactory = new LoggerFactory();

            loggerFactory.AddNLog(new NLogProviderOptions {
                CaptureMessageTemplates = true, CaptureMessageProperties = true
            });
            var logger = loggerFactory.CreateLogger <ApnsPusher>();

            var pusher = new ApnsPusher(logger, keyId, teamId, bundleAppId, keyPath, keyPassword, ApnsEnvironment.Production);

            var notification = new ExtendedApnsNotification
            {
                Payload = new ApnsPayload
                {
                    Alert = new ApnsNotificationAlert
                    {
                        TitleLocalizationKey = "NotificationsService.NewMessage.Title",
                        BodyLocalizationKey  = "NotificationsService.NewMessage.BodySingle"
                    },
                    Badge          = 7,
                    MutableContent = 1
                },
                TxnId         = "",
                PushRecipient = ""
            };

            pusher.OnNotificationSuccess += OnNotificationSuccess;
            pusher.OnNotificationFailed  += OnNotificationFailed;

            Console.WriteLine("Sending notification...");
            pusher.SendNotificationAsync(notification, deviceToken);
            Console.ReadKey();
        }