void UpdateJournal(object sender, EventArgs args) { var calendar = NSCalendar.CurrentCalendar; var startDate = DateTime.Now.Date; var endDate = startDate.AddDays(1); var sampleType = HKSampleType.GetQuantityType(HKQuantityTypeIdentifierKey.DietaryEnergyConsumed); var predicate = HKQuery.GetPredicateForSamples((NSDate)startDate, (NSDate)endDate, HKQueryOptions.None); var query = new HKSampleQuery(sampleType, predicate, 0, new NSSortDescriptor[0], (resultQuery, results, error) => { if (error != null) { Console.WriteLine("An error occured fetching the user's tracked food. " + "In your app, try to handle this gracefully. The error was: {0}.", error.LocalizedDescription); return; } InvokeOnMainThread(() => { FoodItems.RemoveAllObjects(); foreach (HKQuantitySample sample in results) { var foodName = (NSString)sample.Metadata.Dictionary [HKMetadataKey.FoodType]; double joules = sample.Quantity.GetDoubleValue(HKUnit.Joule); var foodItem = FoodItem.Create(foodName, joules); FoodItems.Add(foodItem); } TableView.ReloadData(); }); }); HealthStore.ExecuteQuery(query); }
public override void ViewDidLoad() { base.ViewDidLoad(); FoodItems = NSArray.FromObjects(new object[] { FoodItem.Create("Wheat Bagel", 240000.0), FoodItem.Create("Bran with Raisins", 190000.0), FoodItem.Create("Regular Instant Coffee", 1000.0), FoodItem.Create("Banana", 439320.0), FoodItem.Create("Cranberry Bagel", 416000.0), FoodItem.Create("Oatmeal", 150000.0), FoodItem.Create("Fruits Salad", 60000.0), FoodItem.Create("Fried Sea Bass", 200000.0), FoodItem.Create("Chips", 190000.0), FoodItem.Create("Chicken Taco", 170000.0) }); }