Skip to content

Instantly share code, notes, and snippets.

View gist:1300719
+ (NSString *) uniqueId
{
CFUUIDRef uuid = CFUUIDCreate(NULL);
NSString *identifier =(NSString *)CFUUIDCreateString(NULL, uuid);
CFRelease(uuid);
return [identifier autorelease];
}
View Reading audio samples via AVAssetReader
CMItemCount numSamplesInBuffer = CMSampleBufferGetNumSamples(buffer);
AudioBufferList audioBufferList;
CMSampleBufferGetAudioBufferListWithRetainedBlockBuffer(
buffer,
NULL,
&audioBufferList,
sizeof(audioBufferList),
NULL,
@naotokui
naotokui / gist:1378493
Created Nov 19, 2011
Check if Retina Display is available or not
View gist:1378493
// Check if Retina Display is available or not
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] == YES && [[UIScreen mainScreen] scale] == 2.00){
hasRetina = YES;
}
@naotokui
naotokui / gist:1397437
Created Nov 27, 2011
Get text contents of UIWebView
View gist:1397437
NSString *contents = [webView stringByEvaluatingJavaScriptFromString: @"document.body.innerText"];
@naotokui
naotokui / gist:1581112
Created Jan 9, 2012
Debug NSAutoreleasePool
View gist:1581112
[NSAutoreleasePool showPools]
/* Definition */
extern void _objc_autoreleasePoolPrint();
_objc_autoreleasePoolPrint();
@naotokui
naotokui / gist:1709648
Created Jan 31, 2012
- (UIView *)findFirstResponder
View gist:1709648
- (UIView *) findFirstResonder:(UIView*)root
{
if ([root isFirstResponder]) {
return root;
}
for (UIView *subView in root.subviews) {
UIView *firstResponder = [self findFirstResonder:subView];
if (firstResponder != nil) {
return firstResponder;
@naotokui
naotokui / gist:1756346
Created Feb 7, 2012
- (void) presentModalViewControllerInSizeYouWant (for iPad)
View gist:1756346
- (void) presentModalViewControllerInSizeYouWant
{
float width = <width you wnat>;
float height = <height you wnat>;
UIViewController *viewCtl = [[UIViewController alloc] initWithNibName: @"UIViewController" bundle: nil];
viewCtl.modalPresentationStyle = UIModalPresentationFormSheet; // set presentation style
[self presentModalViewController:viewCtl animated: YES]; // show!
@naotokui
naotokui / gist:1768018
Created Feb 8, 2012
UIView with rounded corners
View gist:1768018
#import <QuartzCore/QuartzCore.h>
view.layer.masksToBounds = YES;
view.layer.cornerRadius = 3.0;
@naotokui
naotokui / gist:3985027
Created Oct 31, 2012
Detect Network Type on iOS ... from the status bar
View gist:3985027
// http://stackoverflow.com/questions/8400340/determining-3g-vs-edge
- (NSNumber *) dataNetworkTypeFromStatusBar {
UIApplication *app = [UIApplication sharedApplication];
NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
NSNumber *dataNetworkItemView = nil;
for (id subview in subviews) {
if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]]) {
@naotokui
naotokui / gist:4063901
Created Nov 13, 2012
UIView RoundedCorner Category
View gist:4063901
#import <QuartzCore/QuartzCore.h>
@implementation UIView (UIView_RoundCorner)
- (void) setCornersRoundedWithRadius: (float) cornerRadius
{
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: self.bounds
byRoundingCorners: UIRectCornerAllCorners
cornerRadii: CGSizeMake(cornerRadius, cornerRadius)];