相关疑难解决方法(0)

在iPhone 3GS上消耗100%CPU的后台线程会导致潜在的主线程

在我的应用程序中,我在NSOperationQueue中执行10个异步NSURLConnections作为NSInvocationOperations.为了防止每个操作在连接有机会完成之前返回,我调用CFRunLoopRun(),如下所示:

- (void)connectInBackground:(NSURLRequest*)URLRequest {
 TTURLConnection* connection = [[TTURLConnection alloc] initWithRequest:URLRequest delegate:self];

 // Prevent the thread from exiting while the asynchronous connection completes the work.  Delegate methods will
 // continue the run loop when the connection is finished.
 CFRunLoopRun();

 [connection release];
}
Run Code Online (Sandbox Code Playgroud)

连接完成后,最终连接委托选择器调用CFRunLoopStop(CFRunLoopGetCurrent())以恢复connectInBackground()中的执行,允许它正常返回:

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    TTURLConnection* ttConnection = (TTURLConnection*)connection;
    ...
    // Resume execution where CFRunLoopRun() was called.
    CFRunLoopStop(CFRunLoopGetCurrent());
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {  
    TTURLConnection* ttConnection = (TTURLConnection*)connection;
    ...
    // Resume execution where CFRunLoopRun() was called.
 CFRunLoopStop(CFRunLoopGetCurrent());
} …
Run Code Online (Sandbox Code Playgroud)

iphone cpu multithreading cocoa-touch objective-c

10
推荐指数
1
解决办法
6210
查看次数

通过代码加热iPhone

好吧,它可能听起来很愚蠢,但我需要找到一段代码来快速温暖iPhone并且不会冻结整个应用程序.有没有人曾经处理过热量和手机?

iphone objective-c ios

0
推荐指数
1
解决办法
661
查看次数

标签 统计

iphone ×2

objective-c ×2

cocoa-touch ×1

cpu ×1

ios ×1

multithreading ×1