This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //------------------------------------------------------------------------------------------------------------------------------ | |
| // Call this function on a button press. The image will be displayed on an Image widget with code name 'ui.photo' | |
| //------------------------------------------------------------------------------------------------------------------------------ | |
| function takePhoto() { | |
| navigator.camera.getPicture(photoSuccess, photoFail, { quality: 15, destinationType : 0 }); | |
| } | |
| // Called when taking a photo works, resizes it and puts it up on the screen for the user. | |
| // Then grabs that as a string and stores it for later uploading. | |
| function photoSuccess(imageString) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
| { | |
| //.. do other setup | |
| CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height; | |
| // Transition neatly from splash screen | |
| // Very odd, on iPhone 5 you need to position the splash screen differently.. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //------------------------------------------------------------------------------------------------------------------------------ | |
| // Call this function on a button press. The image will be displayed on an Image widget with code name 'ui.photo' | |
| //------------------------------------------------------------------------------------------------------------------------------ | |
| function takePhoto() { | |
| navigator.camera.getPicture(photoSuccess, photoFail, { quality: 15, destinationType : 0 }); | |
| } | |
| // Called when taking a photo works, resizes it and puts it up on the screen for the user. | |
| // Then grabs that as a string and stores it for later uploading. | |
| function photoSuccess(imageString) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // e.g. server returns [ {name:"foo"}, {name:"bar} ] | |
| _objectManager = [RKObjectManager managerWithBaseURLString:@"http://example.com/api"]; | |
| RKObjectMapping *rootMapping = [RKObjectMapping mappingForClass:[MyItem class]]; | |
| [rootMapping mapKeyPath:@"name" toAttribute:@"name"]; | |
| [_objectManager.mappingProvider addObjectMapping:rootMapping]; // note this just stores our instance.. | |
| /// LATER ON |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSDictionary* dict = @{@"Status": newStatus ? @"On" : @"Off"}; | |
| NSString* url = @"/api/status"; | |
| [[RKClient sharedClient] post:url usingBlock:^(RKRequest *request) { | |
| [request setBody:dict forMIMEType:RKMIMETypeJSON]; | |
| request.onDidLoadResponse = ^(RKResponse* response) { | |
| NSLog(@"status ok %@", response); | |
| if (completion) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "TTTAttributedLabel.h" | |
| @interface CVSignupViewController : UITableViewController <TTTAttributedLabelDelegate> { | |
| IBOutlet TTTAttributedLabel* _legalLabel; | |
| } | |
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // In IB, set up your UITextFields with tags 1,2,3 | |
| // Set the 'delegate' for each UITextField to be the main ViewController | |
| // Set your ViewController to implement UITextFieldDelegate | |
| // Add function below to your ViewController - use the values in the switch statement to limit the number of chars allowed in each UITextField | |
| - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { | |
| int maxSize; | |
| switch (textField.tag) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NSArray* idsInOrder = @[@"foo", @"bar", @"baz", @"badgers"]; | |
| NSArray* loadedStuff = @[@{@"id":@"baz"}, @{@"id":@"badgers"}, @{@"id":@"wow"}, @{@"id":@"foo"}]; | |
| NSLog(@"UNORDERED: %@", loadedStuff); | |
| NSArray* sorted = [loadedStuff sortedArrayUsingComparator:^NSComparisonResult(NSDictionary* obj1, NSDictionary* obj2) { | |
| // sort by position of id string in order array.. | |
| NSUInteger obj1Pos = [idsInOrder indexOfObject:obj1[@"id"] ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //----------------------------------------------------- | |
| #pragma mark - When the keyboard appears, scroll the tableView up a pre-defined amount, so the content is nicely centered. | |
| //----------------------------------------------------- | |
| // http://stackoverflow.com/questions/1126726/how-to-make-a-uitextfield-move-up-when-keyboard-is-present | |
| // Call this is viewDidLoad | |
| - (void) setupKeyboard { | |
| // register for keyboard notifications | |
| [[NSNotificationCenter defaultCenter] addObserver:self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // UIImage called 'image' | |
| NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); | |
| NSString *documentsDirectory = [paths objectAtIndex:0]; | |
| NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"foo.png"]; | |
| NSData *imageData = UIImagePNGRepresentation(image); | |
| [ imageData writeToURL:[NSURL fileURLWithPath:filePath] atomically:YES]; | |
| NSLog(@"written to %@", filePath); |