This file contains 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
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; | |
if ([device hasTorch]) { | |
[device lockForConfiguration:nil]; | |
[device setTorchMode:AVCaptureTorchModeOn]; // use AVCaptureTorchModeOff to turn off | |
[device unlockForConfiguration]; | |
} |
This file contains 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
- (void)keyboardWillShow:(NSNotification *)aNotification | |
{ | |
// the keyboard is showing so resize the table's height | |
CGRect keyboardRect = [[[aNotification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; | |
NSTimeInterval animationDuration = [[[aNotification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue]; | |
CGRect frame = self.view.frame; | |
frame.size.height -= keyboardRect.size.height; | |
[UIView beginAnimations:@"ResizeForKeyboard" context:nil]; | |
[UIView setAnimationDuration:animationDuration]; | |
self.view.frame = frame; |
This file contains 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)shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string textField:(UITextField *)textField maxLength:(NSUInteger)maxTextFieldLength | |
{ | |
NSUInteger oldLength = [textField.text length]; | |
NSUInteger replacementLength = [string length]; | |
NSUInteger rangeLength = range.length; | |
NSUInteger newLength = oldLength - rangeLength + replacementLength; | |
return newLength <= maxTextFieldLength; | |
} |
This file contains 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
- (IBAction)dimScreenAndShowActivityIndicator:(id)sender { | |
CGRect bounds = self.view.bounds; | |
// Create black view covering entire view | |
UIView *maskView = [[UIView alloc] initWithFrame:bounds]; | |
maskView.backgroundColor = [UIColor blackColor]; | |
[self.view addSubview:maskView]; | |
// Put spinning activity indicator in middle of view | |
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; |
This file contains 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 <SenTestingKit/SenTestingKit.h> | |
@interface JSONTests : SenTestCase | |
@end | |
@implementation JSONTests | |
- (void)testParseJSON { | |
NSBundle *testBundle = [NSBundle bundleForClass:[self class]]; |
This file contains 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 *)readJSONResourceNamed:(NSString *)resourceName { | |
NSString *filePath = [[NSBundle mainBundle] pathForResource:resourceName | |
ofType:@"json"]; | |
NSData *fileData = [NSData dataWithContentsOfFile:filePath]; | |
if (!fileData) | |
return nil; | |
NSError *error = nil; |
This file contains 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
// http://stackoverflow.com/a/9949592/1175 | |
String readStringFromStream(InputStream in) throws IOException { | |
StringBuilder out = new StringBuilder(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(in)); | |
for(String line = br.readLine(); line != null; line = br.readLine()) | |
out.append(line); | |
br.close(); | |
return out.toString(); | |
} |
This file contains 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
public class DeviceInfo { | |
private static final String PREFERENCES = "DeviceInfo.PREFERENCES"; | |
private static final String KEY_DEVICEID = "DeviceId"; | |
/** | |
* @return unique identifier string for the device | |
*/ | |
public static synchronized String getDeviceId(Context context) { | |
SharedPreferences prefs = context.getSharedPreferences(PREFERENCES, 0); |
This file contains 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
public class AppInfo { | |
/** | |
* Get application version string | |
* | |
* @param context | |
* Interface to global information about an application | |
* environment | |
* @return String of the form "VV-CC", where VV is the version name and CC | |
* is the version code (e.g., "1.0.3-25") |
This file contains 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
// Get a reference to the global object (`window` in the browser, `global` on the server). | |
var root = (function () { | |
return this || (0 || eval)('this'); | |
}()); | |
var elemWithId = document.getElementById('anId'); | |
elemWithId.innerHTML = markup; | |
var elemsWithName = document.getElementsByName('aName'); | |
var firstElem = elems[0]; |