Skip to main content

Posts

Showing posts with the label thread

GCD Example

test.h { dispatch_queue_t backgroundQueue ; } test.m - ( void )viewDidLoad {     [ super viewDidLoad ];    //com.unique.uniqueidentifier.youtube is any unique name     backgroundQueue = dispatch_queue_create ( "com.unique.uniqueidentifier.youtube" , NULL );      } -(void)anyFunction {        dispatch_async ( backgroundQueue , ^( void ){              [ self sendRequestForData ];        }); } -( void )sendRequestForData {     NSString *post = @"" ;     NSData *postData = [post dataUsingEncoding : NSISOLatin1StringEncoding allowLossyConversion : NO ];     NSMutableURLRequest *urlRequest = [[[ NSMutableURLRequest alloc ] init ] autorelease ];     [urlRequest setURL :[ NSURL URLWithString: < any url string for fetching dat...

UIWebView crash due to separate thread

Fixed the crash due to separate thread : -(void)viewDidLoad{     NSOperationQueue *operationQueue = [[ NSOperationQueue alloc ] init ]; NSInvocationOperation *operation = [[ NSInvocationOperation alloc ] initWithTarget : self selector : @selector (load) object : nil ]; [operationQueue addOperation :operation]; [operation release ]; [operationQueue release ]; } -( void )load {     [ NSThread sleepForTimeInterval : 1 ];     [ self performSelectorOnMainThread : @selector (loadWebView) withObject : nil waitUntilDone : NO ]; } -( void )loadWebView{     NSLog ( @"Runnnnn...." );           UIWebView *webView = [[ UIWebView alloc ] initWithFrame : self . view . bounds ];     [webView setUserInteractionEnabled : YES ];     NSString *docsDirectory =         [ NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask...