Exemple #1
0
 public void APNS_Feedback_Service ()
 {
     var config = new ApnsConfiguration (
         ApnsConfiguration.ApnsServerEnvironment.Sandbox, 
         Settings.Instance.ApnsCertificateFile, 
         Settings.Instance.ApnsCertificatePassword);
     
     var fbs = new FeedbackService (config);
     fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) => {
         // Remove the deviceToken from your database
         // timestamp is the time the token was reported as expired
     };
     fbs.Check ();
 }
        private void InitApnsBroker(GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment)
        {
            if(string.IsNullOrWhiteSpace(globalSettings.Push.ApnsCertificatePassword)
                || string.IsNullOrWhiteSpace(globalSettings.Push.ApnsCertificateThumbprint))
            {
                return;
            }

            var apnsCertificate = GetCertificate(globalSettings.Push.ApnsCertificateThumbprint);
            if(apnsCertificate == null)
            {
                return;
            }

            var apnsConfig = new ApnsConfiguration(hostingEnvironment.IsProduction() ?
                ApnsConfiguration.ApnsServerEnvironment.Production : ApnsConfiguration.ApnsServerEnvironment.Sandbox,
                apnsCertificate.RawData, globalSettings.Push.ApnsCertificatePassword);

            _apnsBroker = new ApnsServiceBroker(apnsConfig);
            _apnsBroker.OnNotificationFailed += ApnsBroker_OnNotificationFailed;
            _apnsBroker.OnNotificationSucceeded += (notification) =>
            {
                Debug.WriteLine("Apple Notification Sent!");
            };
            _apnsBroker.Start();

            var feedbackService = new FeedbackService(apnsConfig);
            feedbackService.FeedbackReceived += FeedbackService_FeedbackReceived;
            feedbackService.Check();
        }
 private void CheckAndRemoveExpiredToken()
 {
     try
     {
         var fbs = new FeedbackService(config);
         fbs.FeedbackReceived += (string deviceToken, DateTime timestamp) =>
         {
             notificationService.Unsubscribe(deviceToken, userId);
         };
         fbs.Check();
     }
     catch (Exception e)
     {
         logger.ErrorFormat("Unable to usubscibed token" + e.Message);
     }
 }