我的应用程序中有代码可以检测Wi-Fi是否已主动连接.如果启用了飞行模式,该代码会触发RuntimeException.无论如何,我想在此模式下显示单独的错误消息.如何可靠地检测Android设备是否处于飞行模式?
如何从JavaScript中的请求中获取"GET"变量?
是jQuery还是YUI!有内置的这个功能吗?
在当用户按下一个按钮我的应用程序我开始一个HTTP异步请求(使用[NSURLConnection sendAsynchronousRequest...]
)和改变的文本UILabel
中的completionHandler
块.但是,当请求结束时,这种变化不会发生,而是在2-3秒后发生.以下是导致此行为的代码段.
- (IBAction)requestStuff:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:
^(NSURLResponse *response, NSData *data, NSError *error)
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
exampleLabel.text = [NSString stringWithFormat:@"%d", httpResponse.statusCode];
}];
}
Run Code Online (Sandbox Code Playgroud)
当我尝试在UIAlertView
内部创建内部时,会发生类似的行为completionHandler
.
- (IBAction)requestStuff:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://stackoverflow.com/"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler: …
Run Code Online (Sandbox Code Playgroud)