Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 10-15-2010, 08:48 AM   #1 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 19
shivangvyas is on a distinguished road
Smile Connection delegate methods not called with background thread, Why ? (iPhone SDK)

Connection delegate methods not called with background thread, Why ?

In program i have created background thread and that thread set connection delegates, by setting ObjNSURLConnection.delegate = AnotherClass, and that AnotherClass contains NSURLConnection delegate methods.

But when i debug a code i have found that NSURLConnection delegate method doesn't called. Any reason , Why they are not called ? How to solve this issue?
shivangvyas is offline   Reply With Quote
Old 10-15-2010, 09:13 AM   #2 (permalink)
Registered Member
 
Join Date: Oct 2010
Posts: 15
macnikos is on a distinguished road
Default

Quote:
Originally Posted by shivangvyas View Post
Connection delegate methods not called with background thread, Why ?

In program i have created background thread and that thread set connection delegates, by setting ObjNSURLConnection.delegate = AnotherClass, and that AnotherClass contains NSURLConnection delegate methods.

But when i debug a code i have found that NSURLConnection delegate method doesn't called. Any reason , Why they are not called ? How to solve this issue?
I've found myself in the same problem yesterday.

This happens because the thread that created the NSURLConnection no longer exists when it tries to call back its delegate.

My solution was to keep the thread alive until the connection is done:

Code:
-(void)main{

   [self startUpdate]; //This method initializes the NSURLConnection
   
   NSRunLoop *theRL = [NSRunLoop currentRunLoop];
   while (!finished && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]){
       //Keep alive the Thread
   }
  
}
I created an instance variable ("finished") that works as a flag. When the connection did finish to download or fail, it sets the finished flag in true. To achieve this, I worked with the NSNotificationCenter.

I don't know if this is the best solution, but it worked great for me.

Also, I'm using NSOperation and NSOperationQueue here.
macnikos is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone sdk

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 349
7 members and 342 guests
Desert Diva, dre, hain, HemiMG, lendo, mottdog, oceanlablight
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,657
Threads: 94,118
Posts: 402,895
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jenniead38
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:06 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0