Exemplo n.º 1
0
        static void RegisterUserNotificationCategories(NotificationUserCategory[] userCategories)
        {
            if (userCategories != null && userCategories.Length > 0)
            {
                UsernNotificationCategories.Clear();
                IList <UNNotificationCategory> categories = new List <UNNotificationCategory>();
                foreach (var userCat in userCategories)
                {
                    IList <UNNotificationAction> actions = new List <UNNotificationAction>();

                    foreach (var action in userCat.Actions)
                    {
                        // Create action
                        switch (action.Type)
                        {
                        case NotificationActionType.Default:
                            actions.Add(UNNotificationAction.FromIdentifier(action.Id, action.Title, UNNotificationActionOptions.None));
                            break;

                        case NotificationActionType.AuthenticationRequired:
                            actions.Add(UNNotificationAction.FromIdentifier(action.Id, action.Title, UNNotificationActionOptions.AuthenticationRequired));
                            break;

                        case NotificationActionType.Destructive:
                            actions.Add(UNNotificationAction.FromIdentifier(action.Id, action.Title, UNNotificationActionOptions.Destructive));
                            break;

                        case NotificationActionType.Foreground:
                            actions.Add(UNNotificationAction.FromIdentifier(action.Id, action.Title, UNNotificationActionOptions.Foreground));
                            break;

                        case NotificationActionType.Reply:
                            actions.Add(UNTextInputNotificationAction.FromIdentifier(action.Id, action.Title, UNNotificationActionOptions.None, action.Title, string.Empty));
                            break;
                        }
                    }

                    // Create category
                    var categoryID          = userCat.Category;
                    var notificationActions = actions.ToArray() ?? new UNNotificationAction[] { };
                    var intentIDs           = new string[] { };
                    var categoryOptions     = new UNNotificationCategoryOptions[] { };

                    var category = UNNotificationCategory.FromIdentifier(categoryID, notificationActions, intentIDs, userCat.Type == NotificationCategoryType.Dismiss ? UNNotificationCategoryOptions.CustomDismissAction : UNNotificationCategoryOptions.None);
                    categories.Add(category);

                    UsernNotificationCategories.Add(userCat);
                }

                // Register categories
                UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(categories.ToArray()));
            }
        }
Exemplo n.º 2
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            Dictionary <string, object> dict = (Dictionary <string, object>)PListCSLight.readPlist("Info.plist");

            Profile.EnableUpdatesOnAccessTokenChange(true);
            Facebook.CoreKit.Settings.AppID       = dict.GetValueOrDefault("FacebookAppID").ToString();
            Facebook.CoreKit.Settings.DisplayName = dict.GetValueOrDefault("FacebookDisplayName").ToString();

            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            ApplicationDelegate.SharedInstance.FinishedLaunching(app, options);


            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                new NSSet());

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            UIApplication.SharedApplication.RegisterForRemoteNotifications();


            //Create accept action
            var replyId     = "reply";
            var replyTitle  = "Reply";
            var replyAction = UNTextInputNotificationAction.FromIdentifier(replyId, replyTitle, UNNotificationActionOptions.None, "Reply", "Message");



            //Create category
            var categoryID      = "general";
            var actions         = new UNNotificationAction[] { replyAction };
            var intentIDs       = new string[] { };
            var categoryOptions = new UNNotificationCategoryOptions[] { };
            var category        = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);

            //Register category
            var categories = new UNNotificationCategory[] { category };

            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(categories));



            UNUserNotificationCenter.Current.Delegate = new CustomUNUserNotificationCenterDelegate();


            if (options != null && options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
            {
                appIsStarting = true;
            }

            return(base.FinishedLaunching(app, options));
        }
Exemplo n.º 3
0
        /// <summary>
        ///     A method to create and save an Action with Text Input for a specific Category Id.
        ///     See UNTextInputNotificationAction.FromIdentifier.
        /// </summary>
        /// <remarks>
        ///    Should be called before AddCategory for this Category Id in order to have action attached to the category.
        /// </remarks>
        /// <param name="categoryId">Identifier for the Category connected with this Action.</param>
        /// <param name="actionId">
        ///     The string that you use internally to identify the Action.
        ///     This string must be unique among all of your app's supported Actions.
        /// </param>
        /// <param name="title">Localized string that will be displayed on Action button.</param>
        /// <param name="options">Additional options describing how the Action behaves.</param>
        /// <param name="textInputButtonTitle">
        ///     The localized title of the text input button that is displayed to the user.
        /// </param>
        /// <param name="textInputPlaceholder">The localized placeholder text to display in the text input field.</param>
        protected void AddTextInputAction(
            string categoryId,
            string actionId,
            string title,
            UNNotificationActionOptions options,
            string textInputButtonTitle,
            string textInputPlaceholder)
        {
            var action = UNTextInputNotificationAction.FromIdentifier(
                actionId,
                title,
                options,
                textInputButtonTitle ?? string.Empty,
                textInputPlaceholder ?? string.Empty);

            SaveAction(categoryId, action);
        }
Exemplo n.º 4
0
        private void RegisterCategoriesNotification()
        {
            var commentID            = "comment";
            var commentTitle         = "Comment";
            var textInputButtonTitle = "Send";
            var textInputPlaceholder = "Enter comment here...";
            var commentAction        = UNTextInputNotificationAction.FromIdentifier(commentID, commentTitle, UNNotificationActionOptions.None, textInputButtonTitle, textInputPlaceholder);

            // Create category
            var categoryID = "event-invite";
            var actions    = new UNNotificationAction[] { acceptAction, declineAction, commentAction };
            var intentIDs  = new string[] { };
            // actions can be construted by UNTextInputNotificationAction class if you want to actions to that
            // perticular category
            var sampleCategory = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);

            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(new UNNotificationCategory[] { sampleCategory }));
        }
        public static void CreateAction_Category()
        {
            var Actions  = new List <UNNotificationAction>();
            var actionID = string.Empty;
            var title    = string.Empty;

            var actionID1 = "reply";
            var title1    = "Reply";

            var actionID2 = "test";
            var title2    = "Test";

            var textInputButtonTitle = "GO";
            var textInputPlaceholder = "Enter comment here...";

            for (int i = 0; i < 2; i++)
            {
                if (i == 0)
                {
                    actionID = actionID1;
                    title    = title1;
                    var action_input = UNTextInputNotificationAction.FromIdentifier(actionID, title, UNNotificationActionOptions.None, textInputButtonTitle, textInputPlaceholder);
                    Actions.Add(action_input);
                }
                else
                {
                    actionID = actionID2;
                    title    = title2;
                    var action = UNNotificationAction.FromIdentifier(actionID, title, UNNotificationActionOptions.None);
                    Actions.Add(action);
                }
            }

            // Create category
            var categoryID = "message";
            var actions    = Actions.ToArray();
            var intentIDs  = new string[] { };
            var category   = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);

            // Register category
            var categories = new UNNotificationCategory[] { category };

            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(categories));
        }
Exemplo n.º 6
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                new NSSet());

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            UIApplication.SharedApplication.RegisterForRemoteNotifications();


            //Create accept action
            var replyId     = "reply";
            var replyTitle  = "Reply";
            var replyAction = UNTextInputNotificationAction.FromIdentifier(replyId, replyTitle, UNNotificationActionOptions.None, "Reply", "Message");



            //Create category
            var categoryID      = "general";
            var actions         = new UNNotificationAction[] { replyAction };
            var intentIDs       = new string[] { };
            var categoryOptions = new UNNotificationCategoryOptions[] { };
            var category        = UNNotificationCategory.FromIdentifier(categoryID, actions, intentIDs, UNNotificationCategoryOptions.None);

            //Register category
            var categories = new UNNotificationCategory[] { category };

            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(categories));



            UNUserNotificationCenter.Current.Delegate = new CustomUNUserNotificationCenterDelegate();


            if (options != null && options.ContainsKey(UIApplication.LaunchOptionsRemoteNotificationKey))
            {
                appIsStarting = true;
            }

            return(base.FinishedLaunching(app, options));
        }
Exemplo n.º 7
0
        public static void Categoria()
        {
            Console.WriteLine("N0rf3n - EnviarNotificacion/Categoria - Begin ");
            var Accion          = new List <UNNotificationAction>();
            var IdAccion        = "Responder";
            var Titulo          = "Titulo Respuesta";
            var TituloBoton     = "Enviar";
            var MarcaAgua       = "Ingresa tu respuesta";//PlaceHolder
            var RespuestaAccion = UNTextInputNotificationAction.FromIdentifier(IdAccion, Titulo, UNNotificationActionOptions.None, TituloBoton, MarcaAgua);

            Accion.Add(RespuestaAccion);
            var IdCategoria     = "IdentificadorCategoria"; //debe conincidir con el indicado en el envio de la notificacion
            var Acciones        = Accion.ToArray();
            var Identificadores = new String[] { };
            var categoria       = UNNotificationCategory.FromIdentifier(IdCategoria, Acciones, Identificadores, UNNotificationCategoryOptions.None);//Se adjuntan los elementos de la categoria.
            var categorias      = new UNNotificationCategory[] { categoria };

            //Notification Center
            UNUserNotificationCenter.Current.SetNotificationCategories(new NSSet <UNNotificationCategory>(categorias));

            Console.WriteLine("N0rf3n - EnviarNotificacion/Categoria - End ");
        }