Exemplo n.º 1
0
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            window = new UIWindow(UIScreen.MainScreen.Bounds);

            System.Threading.Thread.Sleep(1500);              //splash time

            Parse.SetAppId(appid, clientid);

            /*
             * WithValidParseIds (delegate {
             *  Parse.SetApplicationIdClientKey (appid, clientid);
             *
             * });;
             */

            //loadData ();

            var controller = new UIHomeScreen();

            int firstTime = NSUserDefaults.StandardUserDefaults.IntForKey("firstTime");

            firstTime++;

            NSUserDefaults.StandardUserDefaults.SetInt(firstTime, "firstTime");
            controller.firstTime = firstTime;

            navigationController      = new UINavigationController(controller);
            window.RootViewController = navigationController;

            try
            {
                if (options.ContainsKey(new NSString("UIApplicationLaunchOptionsRemoteNotificationKey")))
                {
                    NSDictionary aps = options.ObjectForKey(new NSString("UIApplicationLaunchOptionsRemoteNotificationKey")) as NSDictionary;

                    Console.WriteLine("entro aqui...");

                    string alert = "NADA";

                    if (aps.ContainsKey(new NSString("alert")))
                    {
                        Console.WriteLine("trae alert aqui...");

                        alert = (aps [new NSString("alert")] as NSString).ToString();

                        alert = alert.Replace("Nuovo evento creato: ", "");

                        app.ApplicationIconBadgeNumber = 0;

                        app.CancelAllLocalNotifications();//.ca

                        controller.gotoEvent = true;
                        controller.keyEvent  = alert;


                        var x = new UIAlertView("iPortogruaro", "Un nuovo evento è stato creato vuoi vedere?", null, "Annullare", "Ok");
                        x.Show();

                        x.Clicked += (sender, buttonArgs) => {
                            int clicked = buttonArgs.ButtonIndex;

                            if (clicked == 1)
                            {
                                var detail = new UIEventDetail(true);
                                detail.key   = alert;
                                detail.Title = "Eventi";
                                this.navigationController.PushViewController(detail, true);
                                //ReceivedRemoteNotification (app, aps);
                            }
                        };
                    }
                    else if (aps.ContainsKey(new NSString("aps")))
                    {
                        Console.WriteLine("NSDictionary: 123");

                        NSDictionary aps2 = aps.ObjectForKey(new NSString("aps")) as NSDictionary;

                        Console.WriteLine("NSDictionary: " + aps2.ToString());
                        alert = (aps2 [new NSString("alert")] as NSString).ToString();

                        alert = alert.Replace("Nuovo evento creato: ", "");

                        Console.WriteLine(alert);

                        app.ApplicationIconBadgeNumber = 0;

                        app.CancelAllLocalNotifications(); //.ca

                        controller.gotoEvent = true;
                        controller.keyEvent  = alert;
                        var detail = new UIEventDetail(true);
                        detail.key   = alert;
                        detail.Title = "Eventi";
                        this.navigationController.PushViewController(detail, true);
                    }
                    else
                    {
                        /*
                         * {
                         * aps =     {
                         * alert = "Nuovo evento creato: Evento Prova Gi\U00f2";
                         * };
                         * }
                         */



                        Console.WriteLine("NSDictionary: " + aps.ToString());

                        JsonValue value = JsonObject.Parse(aps.ToString());

                        Console.WriteLine(value.ToString());

                        JsonValue ar  = value ["aps"];
                        string    msg = "";

                        foreach (JsonValue v in ar)
                        {
                            msg = v ["alert"].ToString().Replace("\"", "");


                            Console.WriteLine("json parse: " + msg);
                        }

                        controller.gotoEvent = true;
                        controller.keyEvent  = msg;
                    }
                }
            }
            catch (Exception ex) {
                Console.WriteLine("error geting the push notifications Error: " + ex.Message);


                if (controller == null)
                {
                    controller = new UIHomeScreen();



                    navigationController      = new UINavigationController(controller);
                    window.RootViewController = navigationController;
                }
            }
            //20130711 start
            if (window.RootViewController == null)
            {
                controller                = new UIHomeScreen();
                navigationController      = new UINavigationController(controller);
                window.RootViewController = navigationController;
            }
            //20130711 end

            // make the window visible
            window.MakeKeyAndVisible();

            //ValidateSetup ();
            //SetupUI ();
            GetLocation();

            //string  newDeviceToken =  NSUserDefaults.StandardUserDefaults.StringForKey("PushDeviceToken");

            //Console.WriteLine("Device Token: " + newDeviceToken);

            registerNotifications();

            return(true);
        }
Exemplo n.º 2
0
 public sourceMainCategory(UIHomeScreen controller, List <iportogruarocategories> _list)
 {
     this.controller = controller;
     list            = _list;
 }