public override void ReceivedRemoteNotification(UIApplication application, NSDictionary userInfo) { ParsePush.HandlePush(userInfo); NSDictionary aps = userInfo.ObjectForKey(new NSString("aps")) as NSDictionary; string alert = ""; if (aps.ContainsKey(new NSString("alert"))) { alert = (aps [new NSString("alert")] as NSString).ToString(); } alert = alert.Replace("Nuovo evento creato: ", ""); var detail = new UIEventDetail(true); detail.key = alert; detail.Title = "Eventi"; this.navigationController.PushViewController(detail, true); application.ApplicationIconBadgeNumber = 0; application.CancelAllLocalNotifications(); //.ca }
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. application.ApplicationIconBadgeNumber = 0; application.CancelAllLocalNotifications(); }
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) { _window = new UIWindow(UIScreen.MainScreen.Bounds); // setup presenter var presenter = new AppPresenter(this, _window); var setup = new Setup(this, presenter); setup.Initialize(); var startup = Mvx.Resolve <IMvxAppStart>(); startup.Start(); _window.MakeKeyAndVisible(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { var notificationSettings = UIUserNotificationSettings.GetSettingsForTypes( UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound, null ); application.CancelAllLocalNotifications(); application.RegisterUserNotificationSettings(notificationSettings); } var session = AVAudioSession.SharedInstance(); NSError categoryError; session.SetCategory(AVAudioSessionCategory.Playback); session.SetActive(true, out categoryError); // check for a notification if (launchOptions != null) { // check for a local notification if (launchOptions.ContainsKey(UIApplication.LaunchOptionsLocalNotificationKey)) { var localNotification = launchOptions[UIApplication.LaunchOptionsLocalNotificationKey] as UILocalNotification; if (localNotification != null) { UIAlertController okayAlertController = UIAlertController.Create(localNotification.AlertAction, localNotification.AlertBody, UIAlertControllerStyle.Alert); okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); Window.RootViewController.PresentViewController(okayAlertController, true, null); // reset our badge UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; } } } return(true);//Facebook.CoreKit.ApplicationDelegate.SharedInstance.FinishedLaunching(application, launchOptions); }
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); }