开发者

How to send downloading process as a background process

开发者 https://www.devze.com 2023-03-26 14:00 出处:网络
I am downloading data from my server it is taking like 5 to 6 minutes for downloading..while downloading I am not able to 开发者_StackOverflow中文版do any work in my application. How to send downloadi

I am downloading data from my server it is taking like 5 to 6 minutes for downloading..while downloading I am not able to 开发者_StackOverflow中文版do any work in my application. How to send downloading process on background so that user can navigate within application and after download. we will inform user downloading completed..

Thank you.


  1. Create the new thread:

[NSThread detachNewThreadSelector:@selector(myMethod) toTarget:self withObject:nil];

  1. Create the method that is called by the new thread:

- (void)myMethod {

       NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

       /*** code that should be run in the new thread goes here ***/

      [pool release];

}

What if you need to do something to the main thread from inside your new thread (for example, show a loading symbol)? Use performSelectorOnMainThread.

[self performSelectorOnMainThread:@selector(myMethod) withObject:nil waitUntilDone:false];


What you need to do is have your downloading code on a separate thread (NSThread on iOS). Here's a tutorial to get you started.

0

精彩评论

暂无评论...
验证码 换一张
取 消