Download File In Background

A Quick & Simple Method Get file //Get file on a background thread to stop GUI locking up dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSData* data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@”http://mydomain.com/comefile.php”]]; [self performSelectorOnMainThread:@selector(fetchedData:) withObject:data waitUntilDone:YES]; });   File Received //*********************************** //*********************************** //********** FILE RECEIVED ********** //*********************************** //*********************************** – (void)fetchedData:(NSData *)responseData { }   A Fuller Featured Method In your .h […]

Read More

Updating UI Controls On Background Threads

It is strongly recommended not to update UI controls etc from a background thread (e.g. a timer, comms etc).  This can be the cause of crashes which are sometimes very hard to identify.  Instead use these to force code to be executed on the UI thread (which is always the “main” thread). Dispatch Async And Dispatch Sync […]

Read More

Read System Volume Setting

Reading the current system audio volume MPMusicPlayerController *iPod = [MPMusicPlayerController iPodMusicPlayer]; float volumeLevel = iPod.volume; NSLog(@”Volume: %f”, volumeLevel); You need to import the MediaPlayer framework and use: #import <MediaPlayer/MediaPlayer.h> Other resources http://stackoverflow.com/questions/7255006/get-system-volume-ios

Read More

C Arrays

Using C Arrays UInt8 MyArray[10]; MyArray[0] = 0x00; MyArray[1] = 0x01; int LengthOfMyArray = length:sizeof(MyArray);

Read More

UIView

Referencing A View In A .xib In #ViewController.h @interface SomeViewController : UIViewController { UIView *MyView; { @property (nonatomic, retain) IBOutlet UIView *MyView; In #ViewController.m @synthesize MyView; //<<<<DON’T FORGET THIS! – (void)viewDidUnload { self.MyView = nil; } Creating Programatically UIView *MyView = [[[UIView alloc] init] autorelease]; Moving A UIView CGRect frame = self.MyView.frame; frame.origin.x = 0; […]

Read More

Get Device IP Address

This code is based on Shivan Raptor’s answer at http://stackoverflow.com/questions/7072989/iphone-ipad-how-to-get-my-ip-address-programmatically //**************************************** //**************************************** //********** GET OUR IP ADDRESS ********** //**************************************** //**************************************** #import #import // Get IP Address – (NSString *)GetOurIpAddress { NSString *address = @”error”; struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL; int success = 0; // retrieve the current interfaces – returns 0 […]

Read More

Disabling App Auto Sleep

If the screen isn’t touched after a time period an iPhone will go to sleep.  Use this to disable this function: //Disable device auto sleep timer [[UIApplication sharedApplication] setIdleTimerDisabled:YES];

Read More

Rich Text Labels

  A label won’t take rich text so you have two choices, use a WebView or multiple labels styled as required. Don’t dismiss the idea of just using multiple labels, even labels over the top of text to highlight individual words.  It’s not pretty but it does work.  One really annoying gotcha of the webview […]

Read More