nsthread

is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread)

↘锁芯ラ 提交于 2019-11-27 20:34:31
问题 Is it ok to use of a notification to communication back to the main thread of an IOS app? (cf performSelectorOnMainThread). That is, there are are there any gottcha's for this purpose? Background want to call back to main UI thread from a background thread (e.g. performSelectorInBackground) could use performSelectorOnMainThread to communicate back, but wondering if it is OK to use a notification? For example [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object

setKeepAliveTimeout and BackgroundTasks

牧云@^-^@ 提交于 2019-11-27 19:16:13
问题 I've a big headache with the topic. I'm working on an application that needs to poll a webserver regularly, in order to check for new data. Based on the returned information, I wish to push a local notification to the user. I know that this approach is slightly different from the one depicted by Apple, in which a remote server makes the work, pushing a remote notification, based on APNS. However, there are many reasons for which i cannot take this approach in consideration. One for all, is

NSThread vs. NSOperationQueue vs. ??? on the iPhone

二次信任 提交于 2019-11-27 17:27:38
Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image]; Alternately: [self performSelectorInBackground:@selector(cacheImage:) withObject:image]; Alternately, I can use an NSOperationQueue NSInvocationOperation *invOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(cacheImage:) object:image]; NSOperationQueue *opQueue = [[NSOperationQueue alloc] init]; [opQueue addOperation:invOperation]; Is there any reason to switch away from NSThread ? GCD is a 4th option when it's

How to pause an NSThread until notified?

泄露秘密 提交于 2019-11-27 13:16:45
I have a worker thread that I want to do one bit of its task, then pause & wait for the "ok, continue" command from another thread, then pause & wait, etc. The use case is: the controlling object is a view that I want to display information about what's going on inside the worker-thread, and allow me to "single-step" through the worker as it does it's thing. The rather ugly and heavy-handed thing that I have in my worker is this: NSLog(@"paused"); paused = YES; while (paused) { [NSThread sleepForTimeInterval:0.25]; } NSLog(@".. continuing"); ...But I can't help but think that there must be a

Help with multi-threading on iOS?

久未见 提交于 2019-11-27 11:05:41
问题 I have an application which utilizes OpenEars and the Flite library. The problem is that the Flite library is resource intensive and it's freezing up my app. I suspect that running Flite on a background thread will fix things, but I have no idea how to do so. That said, how do I implement a background thread in iOS ? I'd appreciate if anyone can point me to some tutorials, share some sample code, or any general advice that would help me solve this problem. 回答1: The Concurrency Programming

Grand Central Dispatch vs. NSThread

筅森魡賤 提交于 2019-11-27 10:22:53
问题 I created some test code for NSThread and Grand Central Dispatch (GCD): - (void)doIt:(NSNumber *)i { sleep(1); NSLog(@"Thread#%i", [i intValue]); } - (IBAction)doWork:(id)sender { for (int i = 0; 10 > i; i++) { NSNumber *t = [NSNumber numberWithInt:i]; [NSThread detachNewThreadSelector:@selector(doIt:) toTarget:self withObject:t]; } sleep(1); dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_apply(10, queue, ^(size_t i) { sleep(1); NSLog(@"GCD#%u

Perform UI Changes on main thread using dispatch_async or performSelectorOnMainThread? [duplicate]

こ雲淡風輕ζ 提交于 2019-11-27 05:36:51
问题 Possible Duplicate: Grand Central Dispatch (GCD) vs. performSelector - need a better explanation To execute "stuff" on the main thread, should I use dispatch_async or performSelectorOnMainThread ? Is there a preferred way, right/or wrong, and/or best practice? Example: I'm performing some logic within the block of an NSURLConnection sendAsynchronousRequest:urlRequest method. Because I'm doing stuff to the main view such as presenting a UIAlertView I need to show the UIAlertView on the main

GCD vs performSelectorInBackground/performSelectorOnMainThread

微笑、不失礼 提交于 2019-11-27 05:29:07
问题 I am new in ios development. I have following questions: When we use GCD(dispatch_group_async, dispatch_async(dispatch_get_main_queue()...) and when we use performSelectorInBackground/performSelectorOnMainThread? What's the differences between those two. I know when we use performSelectorInBackground, we create a new NSThread. But isn't the same when we use dispatch_group_async? Because if we create more than one dispatch_group_async, it means we need to submit more than one blocks in queue.

does NSThread create autoreleasepool automatically now?

◇◆丶佛笑我妖孽 提交于 2019-11-27 02:22:00
问题 I have test code like this - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(test) object:nil]; [thread start]; } -(void)test { MyClass *my = [[[MyClass alloc] init] autorelease]; NSLog(@"%@",[my description]); } I did not create any autoreleasepool for my own thread, but when the thread exit, object "my" just dealloc.why? even though I change my test code as below - (void)viewDidLoad { [super viewDidLoad]; NSThread *thread

NSThread vs. NSOperationQueue vs. ??? on the iPhone

半腔热情 提交于 2019-11-26 22:33:32
问题 Currently I'm using NSThread to cache images in another thread. [NSThread detachNewThreadSelector:@selector(cacheImage:) toTarget:self withObject:image]; Alternately: [self performSelectorInBackground:@selector(cacheImage:) withObject:image]; Alternately, I can use an NSOperationQueue NSInvocationOperation *invOperation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(cacheImage:) object:image]; NSOperationQueue *opQueue = [[NSOperationQueue alloc] init]; [opQueue