Esempio n. 1
0
        public static void SendLocalAlertNotification(BeaconContent message)
        {
            // create the notification
            var notification = new UILocalNotification();
            var keyName      = message.NotificationTitle;

            //The Name can be used to cancel a Local notifications
            var keys     = new object[] { keyName };
            var objects  = new object[] { keyName };
            var userInfo = NSDictionary.FromObjectsAndKeys(objects, keys);


            // set the fire date/time
            notification.FireDate = DateTime.Now.AddSeconds(message.TimeToDisplayInSeconds);
            // configure the alert stuff
            notification.AlertAction = message.NotificationTitle;
            notification.AlertBody   = message.NotificationMessage.ToString();
            notification.UserInfo    = userInfo;

            // modify the badge
            notification.ApplicationIconBadgeNumber += 1;


            // set the sound to be the default sound
            notification.SoundName = UILocalNotification.DefaultSoundName;

            // schedule
            UIApplication.SharedApplication.ScheduleLocalNotification(notification);
        }
 /// <summary>
 /// Sets the retrieved content (from my fake test CMS) and decides how to handle
 /// If in background we use local notifications, else we use screen content changes
 /// </summary>
 /// <param name="content">Content.</param>
 private void SetContent(BeaconContent content)
 {
     if (content != null)
     {
         if (UIApplication.SharedApplication.ApplicationState == UIApplicationState.Active)
         {
             //fire off observer notification
             this.SetValueForKey((BeaconContent)content, new NSString(CoreLocationPropertyName.CustomContent.ToString()));
         }
         else
         {
             if (content.NotificationMessage != string.Empty)
             {
                 //Create and schedule a Local Notification
                 NotificationHelper.SendLocalAlertNotification(content);
             }
         }
     }
 }