Пример #1
0
        public override void OnCreate()
        {
            base.OnCreate();

            CrossCurrentActivity.Current.Init(this);

            //Set the default notification channel for your app when running Android Oreo
            if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }

            FirebasePushNotificationManager.NotificationActivityFlags = Android.Content.ActivityFlags.SingleTop;
            //If debug you should reset the token each time.
#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);
#else
            FirebasePushNotificationManager.Initialize(this, false);
#endif
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            global::Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.SetFlags("FastRenderers_Experimental");
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            global::FFImageLoading.Forms.Platform.CachedImageRenderer.Init(enableFastRenderer: true);
            global::FFImageLoading.ImageService.Instance.Initialize();
            global::ZXing.Net.Mobile.Forms.Android.Platform.Init();
            UserDialogs.Init(this);
            CrossCurrentActivity.Current.Init(this, savedInstanceState);
            Fabric.Fabric.With(this, new Crashlytics.Crashlytics());
            Crashlytics.Crashlytics.HandleManagedExceptions();

            LoadApplication(new App(new AndroidInitializer()));

            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }
            //If debug you should reset the token each time.
//#if DEBUG
//            FirebasePushNotificationManager.Initialize(this, true);
//#else
            FirebasePushNotificationManager.Initialize(this, new ConversePushNotificationHandler(), false);
//#endif
            FirebasePushNotificationManager.ProcessIntent(this, Intent);
        }
Пример #3
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)
        {
            Rg.Plugins.Popup.Popup.Init();

            Xamarin.Forms.Forms.Init();
            Xamarin.Forms.FormsMaterial.Init();

            Control.Init();
            KeyboardOverlapRenderer.Init();
            CachedImageRenderer.Init();
            //CachedImageRenderer.InitImageSourceHandler();

            LoadApplication(new App());

            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                // Request Permissions
                UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound, (granted, error) =>
                {
                    // Do something if needed
                });
            }
            else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null
                    );
                app.RegisterUserNotificationSettings(notificationSettings);
            }

            var task = FirebasePushNotificationManager.Initialize(options);

            //FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert;

            return(base.FinishedLaunching(app, options));
        }
Пример #4
0
        public override void OnCreate()
        {
            base.OnCreate();

            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                FirebasePushNotificationManager.DefaultNotificationChannelId   = "DefaultChannel";
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }


            //If debug you should reset the token each time.
#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);
#else
            FirebasePushNotificationManager.Initialize(this, false);
#endif

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
            };
        }
Пример #5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }


            //If debug you should reset the token each time.
#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);
#else
            FirebasePushNotificationManager.Initialize(this, false);
#endif

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
            };
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
            LoadApplication(new App());
            FirebasePushNotificationManager.ProcessIntent(this, Intent);
            CrossFirebasePushNotification.Current.RegisterForPushNotifications();
            CrossFirebasePushNotification.Current.Subscribe("ipad1");
            //CrossFirebasePushNotification.Current.Reg
        }
Пример #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)
        {
            //popup
            Rg.Plugins.Popup.Popup.Init();

            Xamarin.Forms.Forms.Init();

            FirebasePushNotificationManager.Initialize(options, true);

            UINavigationBar.Appearance.ShadowImage = new UIImage();

            // Init image cropper
            Stormlion.ImageCropper.iOS.Platform.Init();

            //// Init image circle cropper
            ImageCircle.Forms.Plugin.iOS.ImageCircleRenderer.Init();

            FFImageLoading.Forms.Platform.CachedImageRenderer.Init();

            CarouselViewRenderer.Init();

            // Init QR code scanner
            ZXing.Net.Mobile.Forms.iOS.Platform.Init();

            Xamarin.FormsGoogleMaps.Init("AIzaSyC-wryBpQqc8ELEpPBOltvsr6J-voZxcfo", new PlatformConfig
            {
                ImageFactory = new CachingImageFactory()
            });

            LoadApplication(new App());

            //start premind sdk
            Premind.Shared.FinishedLaunching(app, options);

            return(base.FinishedLaunching(app, options));
        }
Пример #7
0
        private void InitPushNotifications()
        {
            if (Build.VERSION.SdkInt >= BuildVersionCodes.O)
            {
                FirebasePushNotificationManager.DefaultNotificationChannelId   = "FirebasePushNotificationChannel";
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }

            var notificationColor = ContextCompat.GetColor(this, Resource.Color.notification);

            FirebasePushNotificationManager.Color        = new Color(notificationColor);
            FirebasePushNotificationManager.IconResource = Resource.Drawable.ic_notification;

            FirebasePushNotificationManager.Initialize(this, new PushNotificationHandler(), false, true, false);

            var notificationContentUI = new NotificationContentUI();

            FirebasePushNotificationManager.RegisterUserNotificationCategories(new[]
            {
                new NotificationUserCategory("message_en", new List <NotificationUserAction>
                {
                    new NotificationUserAction("details", notificationContentUI.TxtDetails.EnUsValue,
                                               NotificationActionType.Foreground),
                    new NotificationUserAction("cancel", notificationContentUI.TxtMarkAsRead.EnUsValue)
                }),
                new NotificationUserCategory("message_ru", new List <NotificationUserAction>
                {
                    new NotificationUserAction("details", notificationContentUI.TxtDetails.RuRuValue,
                                               NotificationActionType.Foreground),
                    new NotificationUserAction("cancel", notificationContentUI.TxtMarkAsRead.RuRuValue)
                })
            });

            CrossFirebasePushNotification.Current.OnNotificationOpened += App.OnNotificationOpened;
            CrossFirebasePushNotification.Current.OnNotificationAction += App.OnNotificationOpened;
        }
Пример #8
0
        public override void OnCreate()
        {
            base.OnCreate();
            RegisterActivityLifecycleCallbacks(this);

            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }

            //If debug you should reset the token each time.
            //         #if DEBUG
            //         FirebasePushNotificationManager.Initialize(this,new NotificationUserCategory[]
            //   {
            //new NotificationUserCategory("message",new List<NotificationUserAction> {
            //    new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
            //    new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)

            //}),
            //new NotificationUserCategory("request",new List<NotificationUserAction> {
            //    new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
            //    new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
            //})

            //   },true);

            //         #else
            //         FirebasePushNotificationManager.Initialize(this, new NotificationUserCategory[]
            //         {
            //         new NotificationUserCategory("message",new List<NotificationUserAction> {
            //             new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
            //             new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)

            //         }),
            //         new NotificationUserCategory("request",new List<NotificationUserAction> {
            //             new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
            //             new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
            //         })

            //     }, false);
            //     #endif

            //         CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            //         {
            //             System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);

            //         };

            //If debug you should reset the token each time.
            #if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);
            #else
            FirebasePushNotificationManager.Initialize(this, false);
            #endif

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
            };
        }
Пример #9
0
        public override void OnCreate()
        {
            base.OnCreate();

            FirebasePushNotificationManager.Initialize(this, false, true);

            RegisterActivityLifecycleCallbacks(this);


            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
            }


            //If debug you should reset the token each time.

#if DEBUG
            FirebasePushNotificationManager.Initialize(this, false);
#else
            FirebasePushNotificationManager.Initialize(this, false);
#endif


            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}");
            };

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
                MainActivity.webContentList = "webContentList";
            };


            CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Opened");
                foreach (var data in p.Data)
                {
                    System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                }
            };


            CrossFirebasePushNotification.Current.OnNotificationAction += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Action");

                if (!string.IsNullOrEmpty(p.Identifier))
                {
                    System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
                    foreach (var data in p.Data)
                    {
                        System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                    }
                }
            };

            CrossFirebasePushNotification.Current.OnNotificationDeleted += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Deleted");
            };


            //#if DEBUG
            //            FirebasePushNotificationManager.Initialize(this, new NotificationUserCategory[]
            //            {
            //            new NotificationUserCategory("message",new List<NotificationUserAction> {
            //                new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
            //                new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)

            //            }),
            //            new NotificationUserCategory("request",new List<NotificationUserAction> {
            //                new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
            //                new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
            //            })

            //            }, true);
            //#else
            //	            FirebasePushNotificationManager.Initialize(this,new NotificationUserCategory[]
            //		    {
            //			new NotificationUserCategory("message",new List<NotificationUserAction> {
            //			    new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
            //			    new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)

            //			}),
            //			new NotificationUserCategory("request",new List<NotificationUserAction> {
            //			    new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
            //			    new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
            //			})

            //		    },false);
            //#endif

            //CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            //{



            //};
        }
Пример #10
0
        public override void OnCreate()
        {
            base.OnCreate();
            RegisterActivityLifecycleCallbacks(this);
            //A great place to initialize Xamarin.Insights and Dependency Services!

            //If debug you should reset the token each time.
#if DEBUG
            FirebasePushNotificationManager.Initialize(this, true);

            /*FirebasePushNotificationManager.Initialize(this, new NotificationUserCategory[]
             * {
             * new NotificationUserCategory("message",new List<NotificationUserAction> {
             *  new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
             *  new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)
             *
             * }),
             * new NotificationUserCategory("request",new List<NotificationUserAction> {
             *  new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
             *  new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
             * })
             *
             * }, true);*/
#else
            FirebasePushNotificationManager.Initialize(this, false);

            /*FirebasePushNotificationManager.Initialize(this,new NotificationUserCategory[]
             * {
             * new NotificationUserCategory("message",new List<NotificationUserAction> {
             *  new NotificationUserAction("Reply","Reply",NotificationActionType.Foreground),
             *  new NotificationUserAction("Forward","Forward",NotificationActionType.Foreground)
             *
             * }),
             * new NotificationUserCategory("request",new List<NotificationUserAction> {
             *  new NotificationUserAction("Accept","Accept",NotificationActionType.Default,"check"),
             *  new NotificationUserAction("Reject","Reject",NotificationActionType.Default,"cancel")
             * })
             *
             * },false);*/
#endif

            //Handle notification when app is closed here
            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("NOTIFICATION RECEIVED", p.Data);
            };


            //Set the default notification channel for your app when running Android Oreo
            if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
            {
                //Change for your default notification channel id here
                FirebasePushNotificationManager.DefaultNotificationChannelId = "DefaultChannel";

                //Change for your default notification channel name here
                FirebasePushNotificationManager.DefaultNotificationChannelName = "general";
            }

            mAuth         = FirebaseAuth.Instance;
            mAuthListener = new FirebaseAuthListener();
            mAuth.AddAuthStateListener(mAuthListener);
        }
Пример #11
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="uiApplication"></param>
        /// <param name="launchOptions"></param>
        /// <returns></returns>
        /// <remarks>You have 17 seconds to return from this method, or iOS will terminate your application.</remarks>
        public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
        {
#if DEBUG
            System.AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                // Set a breakpoint here to catch the unhandled exceptions
                if (e.ExceptionObject is System.Exception ex)
                {
                    System.Console.WriteLine($"UNHANDLEDEXCEPTION: {ex.Message}");
                    System.Console.WriteLine($"UNHANDLEDEXCEPTION: {ex.StackTrace}");
                }
            };
            System.Threading.Tasks.TaskScheduler.UnobservedTaskException += (s, e) =>
            {
                // Set a breakpoint here to catch the unhandled exceptions
                System.Console.WriteLine($"UNHANDLEDEXCEPTION: {e.Exception.Message}");
                System.Console.WriteLine($"UNHANDLEDEXCEPTION: {e.Exception.StackTrace}");
            };
#endif

            SetStatusBar();
            System.Net.ServicePointManager.ServerCertificateValidationCallback += (o, certificate, chain, errors) => true;

            global::Xamarin.Forms.Forms.Init();

            ZXing.Net.Mobile.Forms.iOS.Platform.Init();
            Plugin.InputKit.Platforms.iOS.Config.Init();
            FFImageLoading.Forms.Platform.CachedImageRenderer.Init();
            Google.MobileAds.MobileAds.Configure("ca-app-pub-2210179934394995~1038717065");
            SlideOverKit.iOS.SlideOverKit.Init();
            Plugin.InputKit.Platforms.iOS.Config.Init();
            Rg.Plugins.Popup.Popup.Init();
            OxyPlot.Xamarin.Forms.Platform.iOS.PlotViewRenderer.Init();
            XamEffects.iOS.Effects.Init();
            Shiny.iOSShinyHost.Init(new MyShinyStartup());
            Xamarin.FormsMaps.Init();

            FirebasePushNotificationManager.Initialize(launchOptions, true);

            if (UIDevice.CurrentDevice.CheckSystemVersion(10, 0))
            {
                // Ask the user for permission to get notifications on iOS 10.0+
                UNUserNotificationCenter.Current.RequestAuthorization(
                    UNAuthorizationOptions.Alert | UNAuthorizationOptions.Badge | UNAuthorizationOptions.Sound,
                    (approved, error) => { });

                // Watch for notifications while app is active
                UNUserNotificationCenter.Current.Delegate = new UserNotificationCenterDelegate();
            }
            else if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                // Ask the user for permission to get notifications on iOS 8.0+
                var settings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                    new NSSet());

                UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            }

            application = new App();
            LoadApplication(application);
            return(base.FinishedLaunching(uiApplication, launchOptions));
        }
        protected override void OnCreate(Bundle bundle)
        {
            Instance = this;

            Forms.SetFlags(new[]
            {
                "Expander_Experimental"
            });

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;
            //string refreshedToken=null;

            base.SetTheme(Resource.Style.MainTheme);
            base.OnCreate(bundle);

            Xamarin.Essentials.Platform.Init(this, bundle);

            HtmlLabelRenderer.Initialize();
            FlowListView.Init();

            Rg.Plugins.Popup.Popup.Init(this, bundle);
            CrossCurrentActivity.Current.Init(this, bundle);

            if (!_hasEverInited)
            {
                global::Xamarin.Forms.Forms.Init(this, bundle);
                XF.Material.Droid.Material.Init(this, bundle);
                Rg.Plugins.Popup.Popup.Init(this, bundle);
                //LoadApplication(new App());
                //IsPlayServicesAvailable(); //You can use this method to check if play services are available.
                //CreateNotificationChannel();
                Task.Run(() =>
                {
                    //    //instanceid.DeleteInstanceId();
                    //var instanceid = FirebaseInstanceId.Instance;
                    //Log.Debug("TAG", "{0} {1}", instanceid.Token, instanceid.GetToken(this.GetString(Resource.String.gcm_defaultSenderId), Firebase.Messaging.FirebaseMessaging.InstanceIdScope));

                    //refreshedToken = instanceid.Token;
                });

                if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
                {
                    Window.SetStatusBarColor(Android.Graphics.Color.Black);
                }

                if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
                {
                    FirebasePushNotificationManager.DefaultNotificationChannelId   = "DefaultChannel";
                    FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
                }
                FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.High;

#if DEBUG
                FirebasePushNotificationManager.Initialize(this, false);
#else
                FirebasePushNotificationManager.Initialize(this, false);
#endif

                LoadApplication(new App());

                FirebasePushNotificationManager.ProcessIntent(this, Intent);
                FirebasePushNotificationManager.IconResource = Resource.Drawable.ic_stat_appstore;
                FirebasePushNotificationManager.Color        = Color.FromHex("#000000").ToAndroid();
                //LoadApplication(new App(refreshedToken));
            }
        }
        //
        // 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();

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                var pushSettings = UIUserNotificationSettings.GetSettingsForTypes(
                    UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound,
                    new NSSet());

                UIApplication.SharedApplication.RegisterUserNotificationSettings(pushSettings);
                UIApplication.SharedApplication.RegisterForRemoteNotifications();
            }
            else
            {
                UIRemoteNotificationType notificationTypes = UIRemoteNotificationType.Alert | UIRemoteNotificationType.Badge | UIRemoteNotificationType.Sound;
                UIApplication.SharedApplication.RegisterForRemoteNotificationTypes(notificationTypes);
            }

            FirebasePushNotificationManager.Initialize(options, true);
            CrossFirebasePushNotification.Current.RegisterForPushNotifications();

            CrossFirebasePushNotification.Current.OnTokenRefresh += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine($"TOKEN : {p.Token}");
                //   UserDialogs.Instance.AlertAsync(p.Token);

                UIPasteboard clipboard = UIPasteboard.General;
                clipboard.String     = p.Token;
                Settings.DeviceToken = p.Token;
                //var stack = new StackLayout();
                //var btn = new Button() {Text = "Click"};
                //stack.Children.Add(new Entry() { Text = p.Token });
                //stack.Children.Add(btn);
                //var testpage = new TestPage(){Content = stack};
                //App.Current.MainPage = testpage;
                //btn.Clicked += (ss, e) => { App.Current.MainPage = new Login(); };
            };
            //      Push message received event usage sample:

            CrossFirebasePushNotification.Current.OnNotificationReceived += (s, p) =>
            {
                System.Diagnostics.Debug.WriteLine("Received");
                Dictionary <string, string> dic = p.Data as Dictionary <string, string>;

                NotificationBO notificationBo = new NotificationBO();

                FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert;


                foreach (var item in p.Data)
                {
                    if (item.Key.Contains("title"))
                    {
                        notificationBo.Title = Convert.ToString(item.Value);
                    }
                    if (item.Key.Contains("message"))
                    {
                        notificationBo.Message = Convert.ToString(item.Value);
                    }
                    if (item.Key.Contains("screen"))
                    {
                        notificationBo.Screen = Convert.ToString(item.Value);
                    }
                    if (item.Key.Contains("body"))
                    {
                        notificationBo.Body = Convert.ToString(item.Value);
                    }
                    if (item.Key == "sound")
                    {
                        notificationBo.Sound = Convert.ToString(item.Value);
                    }
                    if (item.Key.Contains("content_available"))
                    {
                        notificationBo.ContentAvailable = Convert.ToString(item.Value);
                    }
                }

                App.Database.InsertNotification(notificationBo);


                ProcessNotification(dic, false);
            };
            // Push message opened event usage sample:


            CrossFirebasePushNotification.Current.OnNotificationOpened += (s, p) =>
            {
                App.Current.MainPage = new MainPage()
                {
                    Detail = new NavigationPage(new NotificationsPage())
                };

                //System.Diagnostics.Debug.WriteLine("Opened");
                //foreach (var data in p.Data)
                //{
                //    System.Diagnostics.Debug.WriteLine($"{data.Key} : {data.Value}");
                //}

                //if (!string.IsNullOrEmpty(p.Identifier))
                //{
                //    System.Diagnostics.Debug.WriteLine($"ActionId: {p.Identifier}");
                //}
            };

            LoadApplication(new App());


            SlideOverKit.iOS.SlideOverKit.Init();
            return(base.FinishedLaunching(app, options));
        }
Пример #14
0
 // class-level declarations
        public override UIWindow Window
        {
            get;
            set;
        }

        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            App.Initialize();
            var user = NSUserDefaults.StandardUserDefaults;
            if (user.BoolForKey("hasRunBefore") == false)
            {
                KeyChainHelper.DeleteKey("Usuario_Id");
                KeyChainHelper.DeleteKey("Usuario_Tipo");
                KeyChainHelper.DeleteKey("Empresa_Id");
                user.SetBool(true, "hasRunBefore");
                user.Synchronize();
            }

            UIApplication.SharedApplication.StatusBarHidden = false;
            application.SetStatusBarStyle(UIStatusBarStyle.LightContent, true);
            UINavigationBar.Appearance.BarTintColor = UIColor.Black;
            UINavigationBar.Appearance.TintColor = UIColor.White;
            UINavigationBar.Appearance.SetTitleTextAttributes(new UITextAttributes() { TextColor = UIColor.White });
            UINavigationBar.Appearance.Translucent = false;

            var result = false;

            if (InternetConectionHelper.VerificarConexion())
     {
                MenuHelper.GetListConfiguraciones();
                if (MenuHelper.Configuraciones != null)
                {
                    var configuracionCorreo = MenuHelper.Configuraciones.Find(parametro => parametro.Parametro_Descripcion == "REGEX Y LONGITUD DE CORREO ELECTRONICO DEL USUARIO"); //new ConfigurationsController().GetConfiguraciones("REGEX Y LONGITUD DE CORREO ELECTRONICO DEL USUARIO");
                    var configuracionPassword = MenuHelper.Configuraciones.Find(parametro => parametro.Parametro_Descripcion == "REGEX Y LONGITUD DE CONTRASEÑA DEL USUARIO");//new ConfigurationsController().GetConfiguraciones("REGEX Y LONGITUD DE CONTRASEÑA DEL USUARIO");
                    if ((configuracionCorreo == null || configuracionPassword == null))
                    {
                        Window.RootViewController = UIStoryboard.FromName("Main", null).InstantiateViewController("NoConexion");
                    }
                    else
                    {
                        MenuHelper.UploadImagePath = MenuHelper.Configuraciones.Find(parametro => parametro.Parametro_Descripcion == "RUTA DE IMAGENES DE PUBLICACIONES").Parametro_Varchar_1;
                        MenuHelper.ProfileImagePath = MenuHelper.Configuraciones.Find(parametro => parametro.Parametro_Descripcion == "RUTA DE IMAGENES DE PERFILES DE USUARIOS").Parametro_Varchar_1;
                        result = KeyChainHelper.SetKey("EmailRegex", configuracionCorreo.Parametro_Varchar_1);
                        result = KeyChainHelper.SetKey("LongitudEmail", configuracionCorreo.Parametro_Varchar_2);
                        result = KeyChainHelper.SetKey("PasswordRegex", configuracionPassword.Parametro_Varchar_1);
                        result = KeyChainHelper.SetKey("LongitudPassword", configuracionPassword.Parametro_Varchar_2);
                    }
                    if (!string.IsNullOrEmpty(KeyChainHelper.GetKey("Usuario_Id")) && !string.IsNullOrEmpty(KeyChainHelper.GetKey("Usuario_Tipo")))
                    {
                        MenuHelper.GetUsuarioInfo();
                        Window.RootViewController = UIStoryboard.FromName("Main", null)
                            .InstantiateViewController("NavEscritorio");
                    }
                    else
                    {
                        var controller = UIStoryboard.FromName("Main", null).InstantiateViewController("LoginViewController");
                        controller.Title = "Iniciar Sesión";
                        Window.RootViewController = controller;
                    }
                }
                else
                {
                    Window.RootViewController = UIStoryboard.FromName("Main", null).InstantiateViewController("NoConexion");
                }
     }
     else
     {
                Window.RootViewController = UIStoryboard.FromName("Main", null).InstantiateViewController("NoConexion");
            }
            UIApplication.SharedApplication.RegisterForRemoteNotifications();
            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert, new NSSet());
            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
            FirebasePushNotificationManager.Initialize(launchOptions, true);
            UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {
                // Handle approval
            });
            // Get current notification settings
            UNUserNotificationCenter.Current.GetNotificationSettings ((set) => {
                var alertsAllowed = (set.AlertSetting == UNNotificationSetting.Enabled);
            }); 
                // Enable or disable features based on authorization.
            UNUserNotificationCenter.Current.Delegate = new UNUserNotificationCenterDelegate();

            return true;
        }

        public override void OnResignActivation(UIApplication application)
        {
            // Invoked when the application is about to move from active to inactive state.
            // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 
            // or when the user quits the application and it begins the transition to the background state.
            // Games should use this method to pause the game.
        }


        public override void WillEnterForeground(UIApplication application)
        {
            // Called as part of the transiton from background to active state.
            // Here you can undo many of the changes made on entering the background.
        }


        public override void WillTerminate(UIApplication application)
        {
            // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground.
        }

        public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken)
        {
            FirebasePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);
        }


        public override void FailedToRegisterForRemoteNotifications(UIApplication application, NSError error)
        {
            FirebasePushNotificationManager.RemoteNotificationRegistrationFailed(error);


        }
        // To receive notifications in foregroung on iOS 9 and below.
        // To receive notifications in background in any iOS version
        public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
        {