Skip to content

Instantly share code, notes, and snippets.

@jault3
jault3 / PopulateHeight.m
Last active August 29, 2015 14:06
Populate Height from HealthKit
HKQuantityType *heightType = [HKQuantityType quantityTypeForIdentifier:HKQuantityTypeIdentifierHeight];
// Since we are interested in retrieving the user's latest sample
// we sort the samples in descending order by end date
// and set the limit to 1
NSSortDescriptor *timeSortDescriptor = [[NSSortDescriptor alloc] initWithKey:HKSampleSortIdentifierEndDate ascending:NO];
// construct the query & since we are not filtering the data the predicate is set to nil
HKSampleQuery *query = [[HKSampleQuery alloc] initWithSampleType:heightType predicate:nil limit:1 sortDescriptors:@[timeSortDescriptor] resultsHandler:^(HKSampleQuery *query, NSArray *results, NSError *error) {
@jault3
jault3 / Environment.swift
Created August 18, 2014 22:46
Environment.swift
import Foundation
class Environment {
var environmentId: String
var data: Dictionary<String, AnyObject>
var deployed: Bool
var dirty: Bool
init(dict: Dictionary<String, AnyObject>) {
self.environmentId = (dict["environmentId"] as AnyObject?) as String
@jault3
jault3 / messages.json
Last active August 29, 2015 14:04
Messages Schema
{
"name":"messages",
"schema":{
"msgContent":"string",
"toPhone":"string",
"fromPhone":"string",
"timestamp":"string",
"isPhi":"boolean",
"fileId":"string",
"conversationsId":"string"
@jault3
jault3 / contacts.json
Created July 17, 2014 14:09
Contacts Schema
{
"name":"contacts",
"schema":{
"user_username":"string",
"user_usersId":"string"
},
"phi":false
}
@jault3
jault3 / conversations.json
Last active August 29, 2015 14:04
Conversations Schema
{
"name":"conversations",
"schema":{
"sender":"string",
"recipient":"string",
"sender_id":"string",
"recipient_id":"string"
},
"phi":true
}
@jault3
jault3 / CurrentUser.m
Created June 25, 2014 17:57
Get Current User
[CatalyzeUser currentUser];
@jault3
jault3 / LogIn.m
Created June 25, 2014 17:57
Log In
- (IBAction)login:(id)sender {
[CatalyzeUser logInWithUsernameInBackground:_txtUsername.text password:_txtPassword.text block:^(int status, NSString *response, NSError *error) {
if (error) {
[[[UIAlertView alloc] initWithTitle:@"Error" message:@"Invalid username / password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil] show];
} else {
[self.navigationController pushViewController:[[HealthTrackerViewController alloc] initWithNibName:nil bundle:nil] animated:YES];
}
}];
}
@jault3
jault3 / CatalyzeSignUp.m
Created June 25, 2014 17:55
Catalyze Sign Up
- (IBAction)signUp:(id)sender {
Email *email = [[Email alloc] init];
[email setPrimary:_txtEmail.text];
Name *name = [[Name alloc] init];
[name setFirstName:_txtFirstName.text];
[name setLastName:_txtLastName.text];
[CatalyzeUser signUpWithUsernameInBackground:_txtUsername.text email:email name:name password:_txtPassword.text block:^(int status, NSString *response, NSError *error) {
if (error) {
@jault3
jault3 / CatalyzeLogout.m
Created June 25, 2014 16:32
Catalyze Logout
- (void)logout {
[[CatalyzeUser currentUser] logoutWithBlock:^(int status, NSString *response, NSError *error) {
[self.navigationController popViewControllerAnimated:YES];
}];
}
@jault3
jault3 / QuerySurveys.m
Created June 25, 2014 16:30
Query Surveys
CatalyzeQuery *query = [CatalyzeQuery queryWithClassName:@"surveys"];
[query setPageSize:20];
[query setPageNumber:1];
[query retrieveInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (objects) {
_surveys = [NSMutableArray array];
_otherSurveys = [NSMutableArray array];
for (NSDictionary *dict in objects) {
if ([[dict valueForKey:@"parentId"] isEqualToString:[[CatalyzeUser currentUser] usersId]]) {