Esempio n. 1
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Create a Accept action
            UIMutableUserNotificationAction acceptAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "ACCEPT_ID",
                Title                  = "Accept",
                ActivationMode         = UIUserNotificationActivationMode.Background,
                Destructive            = false,
                AuthenticationRequired = false
            };

            // Create a Reply action
            UIMutableUserNotificationAction replyAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "REPLY_ID",
                Title                  = "Reply",
                ActivationMode         = UIUserNotificationActivationMode.Foreground,
                Destructive            = false,
                AuthenticationRequired = true
            };

            // Create a Trash action
            UIMutableUserNotificationAction trashAction = new UIMutableUserNotificationAction()
            {
                Identifier             = "TRASH_ID",
                Title                  = "Trash",
                ActivationMode         = UIUserNotificationActivationMode.Background,
                Destructive            = true,
                AuthenticationRequired = true
            };

            // Create MonkeyMessage Category
            UIMutableUserNotificationCategory monkeyMessageCategory = new UIMutableUserNotificationCategory();

            monkeyMessageCategory.Identifier = "MONKEYMESSAGE_ID";
            monkeyMessageCategory.SetActions(new UIUserNotificationAction[] { acceptAction, replyAction, trashAction }, UIUserNotificationActionContext.Default);
            monkeyMessageCategory.SetActions(new UIUserNotificationAction[] { acceptAction, trashAction }, UIUserNotificationActionContext.Minimal);

            // Create a category group
            NSSet categories = new NSSet(monkeyMessageCategory);

            // Set the requested notification types
            UIUserNotificationType type = UIUserNotificationType.Alert | UIUserNotificationType.Badge;

            // Create the setting for the given types
            UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(type, categories);

            // Register the settings
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

            //Completed
            return(true);
        }
Esempio n. 2
0
		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			// Create a Accept action
			UIMutableUserNotificationAction acceptAction = new UIMutableUserNotificationAction (){
				Identifier = "ACCEPT_ID",
				Title = "Accept",
				ActivationMode = UIUserNotificationActivationMode.Background,
				Destructive = false,
				AuthenticationRequired = false
			};

			// Create a Reply action
			UIMutableUserNotificationAction replyAction = new UIMutableUserNotificationAction () {
				Identifier = "REPLY_ID",
				Title = "Reply",
				ActivationMode = UIUserNotificationActivationMode.Foreground,
				Destructive = false,
				AuthenticationRequired = true
			};

			// Create a Trash action
			UIMutableUserNotificationAction trashAction = new UIMutableUserNotificationAction (){
				Identifier = "TRASH_ID",
				Title = "Trash",
				ActivationMode = UIUserNotificationActivationMode.Background,
				Destructive = true,
				AuthenticationRequired = true
			};

			// Create MonkeyMessage Category
			UIMutableUserNotificationCategory monkeyMessageCategory = new UIMutableUserNotificationCategory ();
			monkeyMessageCategory.Identifier = "MONKEYMESSAGE_ID";
			monkeyMessageCategory.SetActions (new UIUserNotificationAction[]{ acceptAction, replyAction, trashAction }, UIUserNotificationActionContext.Default);
			monkeyMessageCategory.SetActions (new UIUserNotificationAction[]{ acceptAction, trashAction }, UIUserNotificationActionContext.Minimal);

			// Create a category group
			NSSet categories = new NSSet(monkeyMessageCategory);

			// Set the requested notification types
			UIUserNotificationType type = UIUserNotificationType.Alert | UIUserNotificationType.Badge;

			// Create the setting for the given types
			UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(type, categories);

			// Register the settings
			UIApplication.SharedApplication.RegisterUserNotificationSettings (settings);

			//Completed
			return true;
		}
        public static void RegisterNotifications()
        {
            var action = new UIMutableUserNotificationAction
                {
                    Title = "Launch",
                    Identifier = "trade",
                    ActivationMode = UIUserNotificationActivationMode.Foreground,
                    AuthenticationRequired = false
                };

            var actionCategory = new UIMutableUserNotificationCategory { Identifier = "trade" };

            var categories = new NSMutableSet();
            categories.Add(actionCategory);

            actionCategory.SetActions(new UIUserNotificationAction[] { action }, UIUserNotificationActionContext.Default);

            var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Sound, categories);
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
        }
        public override string Send(Notification notification)
        {
            var not = new UILocalNotification {
                FireDate    = (NSDate)notification.SendTime,
                AlertAction = notification.Title,
                AlertBody   = notification.Message,
                SoundName   = notification.Sound
            };
            var msgId = Guid.NewGuid().ToString();

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0) && notification.Actions.Any())
            {
                var category = new UIMutableUserNotificationCategory {
                    Identifier = Guid.NewGuid().ToString()
                };
                var actions = notification
                              .Actions
                              .Select(x => new UIMutableUserNotificationAction {
                    Title                  = x.Title,
                    Identifier             = x.Identifier,
                    Destructive            = x.IsDestructive,
                    AuthenticationRequired = false,
                    ActivationMode         = x.IsBackgroundAction
                            ? UIUserNotificationActivationMode.Background
                            : UIUserNotificationActivationMode.Foreground
                })
                              .ToArray();

                category.SetActions(actions, UIUserNotificationActionContext.Default);
                var catSet   = new NSSet(category);
                var settings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                    catSet
                    );
                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                not.Category = category.Identifier;
            }

            UIApplication.SharedApplication.ScheduleLocalNotification(not);
            return(msgId);
        }
Esempio n. 5
0
        public static void RegisterNotifications()
        {
            var action = new UIMutableUserNotificationAction
            {
                Title                  = "Launch",
                Identifier             = "trade",
                ActivationMode         = UIUserNotificationActivationMode.Foreground,
                AuthenticationRequired = false
            };

            var actionCategory = new UIMutableUserNotificationCategory {
                Identifier = "trade"
            };

            var categories = new NSMutableSet();

            categories.Add(actionCategory);

            actionCategory.SetActions(new UIUserNotificationAction[] { action }, UIUserNotificationActionContext.Default);

            var settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert | UIUserNotificationType.Sound, categories);

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
        }
Esempio n. 6
0
		protected void RegisterNotifications (UIApplication application)
		{
			var lightsSwitchAction = new UIMutableUserNotificationAction {
				Identifier = LightsSwitchIdentifier,
				Title = "Zet lampen uit en aan",
				ActivationMode = UIUserNotificationActivationMode.Background,
				AuthenticationRequired = false,
				Destructive = true
			};
			var lightsOnAction = new UIMutableUserNotificationAction {
				Identifier = LightsOnIdentifier,
				Title = "Zet lampen aan",
				ActivationMode = UIUserNotificationActivationMode.Background,
				AuthenticationRequired = false
			};
			var lightsOffAction = new UIMutableUserNotificationAction {
				Identifier = LightsOffIdentifier,
				Title = "Zet lampen uit",
				ActivationMode = UIUserNotificationActivationMode.Background,
				AuthenticationRequired = false,
				Destructive = true
			};
					
			var switchRoomCategory = new UIMutableUserNotificationCategory {
				Identifier = SwitchRoomCategory
			};
			switchRoomCategory.SetActions (new UIUserNotificationAction[] {
				lightsSwitchAction, lightsOnAction, lightsOffAction
			}, UIUserNotificationActionContext.Default);
			switchRoomCategory.SetActions (new UIUserNotificationAction[] {
				lightsSwitchAction, lightsOnAction, lightsOffAction
			}, UIUserNotificationActionContext.Minimal);

			var enterRoomCategory = new UIMutableUserNotificationCategory {
				Identifier = EnterRoomCategory
			};
			enterRoomCategory.SetActions (new UIUserNotificationAction[] { lightsOnAction }, UIUserNotificationActionContext.Default);
			enterRoomCategory.SetActions (new UIUserNotificationAction[] { lightsOnAction }, UIUserNotificationActionContext.Minimal);

			var leftRoomCategory = new UIMutableUserNotificationCategory {
				Identifier = LeftRoomCategory
			};
			leftRoomCategory.SetActions (new UIUserNotificationAction[] { lightsOffAction }, UIUserNotificationActionContext.Default);
			leftRoomCategory.SetActions (new UIUserNotificationAction[] { lightsOffAction }, UIUserNotificationActionContext.Minimal);

			var categories = new NSSet (switchRoomCategory, enterRoomCategory, leftRoomCategory);
			var settings = UIUserNotificationSettings.GetSettingsForTypes (UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, categories);
			application.RegisterUserNotificationSettings (settings);
		}
		/// <summary>
		/// Gets the categories to be registered for push notifications.
		/// </summary>
		/// <returns></returns>
		public async Task<NSSet> GetCategoriesAsync()
		{
			var set = new NSMutableSet();

			var config = await GetConfigurationAsync();
			
			// The configuration of the categories has to be on the main thread so we'll need to wait for
			// this to finish

			var waitHandle = new ManualResetEvent(false);
			
			UIApplication.SharedApplication.InvokeOnMainThread(() =>
			{
				if (config != null)
				{
					foreach (var buttonSet in config)
					{
						foreach (var suffix in _suffixes)
						{
							var category = new UIMutableUserNotificationCategory
							{
								Identifier = buttonSet.ButtonSetId + suffix
							};

							var currentSuffix = suffix;
							var index = -1;
							var actions = buttonSet.ButtonValues.Select(v =>
								new UIMutableUserNotificationAction
								{
									ActivationMode = GetActivationMode(currentSuffix[index += 2]),
									Identifier = v,
									Title = v,
									Destructive = false,
									AuthenticationRequired = false
								})
								.Cast<UIUserNotificationAction>()
								.ToArray();
							category.SetActions(actions, UIUserNotificationActionContext.Default);
							category.SetActions(actions, UIUserNotificationActionContext.Minimal);

							set.Add(category);
						}
					}
				}

				waitHandle.Set();
			});

			// this will block the background thread, but only for a short period
			waitHandle.WaitOne();

			return set;
		}