guard let quantityType = HKObjectType.quantityTypeForIdentifier(HKQuantityTypeIdentifierHeartRate) else { return nil } let heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in guard let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) } heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in self.anchor = newAnchor! self.updateHeartRate(samples) } return heartRateQuery } let heartRateQuery = HKAnchoredObjectQuery(type: quantityType, predicate: predicate, anchor: anchor, Int(HKObjectQueryNoLimit)) { (query, sampleObjects, deletedObjects, newAnchor, error) -> Void in let newAnchor = newAnchor else {return} self.anchor = newAnchor self.updateHeartRate(sampleObjects) This will make the watch start measuring the Heart rate heartRateQuery.updateHandler = {(query, samples, deleteObjects, newAnchor, error) -> Void in self.anchor = newAnchor! self.updateHeartRate(samples) This will save the value of the heart rate with the value the watch measures it. This function updateHeartRate will if the heart rate crosses certain level. func updateHeartRate(samples: [HKSample]?) {
if(CMMotionActivityManager. isActivityAvailable()){ This will check if CNNotionActivityManager is available on the system or not because before iOS 7 you can not use it. withHandler: { (data:CMMotionActivity?) -> Void in if ((data?.walking) == true || (data?.running) == true) { } else{ print("not walking"); if activity manager is active it will use the iPhone sensor to if the user is moving or not. = 1 This will if there are update every 1 second. print("Number of steps = \(data.numberOfSteps)") let steps : NSNumber = data.numberOfSteps let strConvert = String(steps) This should count the number of steps and save it. let errorAlert = UIAlertView(title: "You are Running or walking now", message:strConvert, delegate: self, cancelButtonTitle: "OK") errorAlert.show() let secondController = SecondViewController() secondController.activateExcercise() If the user is moving the phone should show him that it is tracking his movement by showing him this message.
NSUserDefaults.standardUserDefaults() .setObject(todoDictionary, forKey: ITEMS_KEY) This will save/overwrite todo item list let notification = UILocalNotification() notification.alertBody = "Todo Item \"\(item.title)\" Is Overdue" This will create the medicine reminder notification and shows what the text will be on the notification. notification.alertAction = "open" This is the text that is displayed after "slide to..." on the lock screen - defaults to "slide to view" self.setBadgeNumbers() This will update the on adding new item So, when Medicine reminder notification shows the user has two choices: one is to press Complete if he took the medicine and the other option is to remind him in 30 minutes and this is the function that do the reminder: func scheduleReminderforItem(item: TodoMedicineItem) { let notification = UILocalNotification() // create a new reminder notification notification.alertBody = "Medicine Intake\"\(item.title)\" Is Overdue" // text that will be displayed in the notification notification.alertAction = "open" // text that is displayed "slide to..." on the lock screen - defaults to "slide to view" notification.fireDate = NSDate().dateByAddingTimeInterval(30 * 60) notification.soundName = UILocalNotificationDefaultSoundName // play default sound notification.userInfo = ["title": item.title, "UUID": item.UUID] notification.category = "TODO_CATEGORY" UIApplication.sharedApplication().scheduleLocalNotification(notification) } notification.fireDate = NSDate().dateByAddingTimeInterval(30 * 60) When the user choose remind me in 30 minutes this is will calculate
[Yoo2013] Yoo, Jin-Hong. "The meaning information technology (IT) mobile devices to me, the infectious disease physician." Infection & chemotherapy 45.2 (2013): 244-251. [GreatCall] [Appledeveloper] [Tom2014] Tom Harrington “Sharing data between iOS apps and app extensions” (2014) http://www.atomicbird.com/blog/sharing-with-app-extensions [Miller2014] Jen A. Miller “The Future of mHealth Goes Well Beyond Fitness Apps” (2014) [JOVVH2014 Jennifer M. Ortman, Victoria A. Velkoff, and Howard Hogan “ An Aging Nation: The older population in the United States.” May 2014.