我想知道如何仅从URL请求异步获取返回值1或0 ....
目前我是这样做的:
NSString *UTCString = [NSString stringWithFormat:@"http://web.blah.net/question/CheckQuestions?utc=%0.f",[lastUTCDate timeIntervalSince1970]];
NSLog(@"UTC String %@",UTCString);
NSURL *updateDataURL = [NSURL URLWithString:UTCString];
NSString *checkValue = [NSString stringWithContentsOfURL:updateDataURL encoding:NSASCIIStringEncoding error:Nil];
NSLog(@"check Value %@",checkValue);
这是有效的,但是它阻止了我的主线程,直到我从URL得到回复,我该如何设置它以便它将在另一个线程而不是主线程中执行?
编辑:ANSWER 我最终用这个来调用我的功能,它运行良好:)
[self performSelectorInBackground:@selector(shouldCheckForUpdate) withObject:nil];
我在这里认真对待大脑放屁,但我无法弄清楚为什么这不符合我的生活.一直在搜索,我甚至无法获取代码样本进行编码.有任何想法吗?
NSString *searchString = @"waffl&es";
NSString *encodedSearchString = [searchString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = [NSString stringWithFormat:@"http://en.wikipedia.org/?search=%@", encodedSearchString];
NSURL *url = [NSURL URLWithString:urlString];
我正在开发一个带有最新SDK和XCode 4.2的iOs 4应用程序.
我正在使用Web服务来检索一些数据,并且我收到了这些数据.但是,当我这样做
NSString *json_string = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
receivedData有944字节但是json_string没有.
从Web服务我得到这个字符串(从浏览器窗口复制和粘贴):
{"posts": [ { "ID": "324","fecha": "10/02/2012","titulo": "Preparada para la lluvia","texto": "¡Al mal tiempo buena cara! Eso pensé al vestirme el otro dÃa que hiz...","foto": "2012/02/image20.jpg" } ] }
我试图在这里验证JSON,http://jsonformatter.curiousconcept.com/,但我觉得它无效.告诉我这个格式化的输出:
{
   "posts":[
      {
         "ID":"324",
         "fecha":"10/02/2012",
         "titulo":"Preparada para la lluvia",
         "texto":,
         "foto":"2012/02/image20.jpg"
      }
   ]
}
这个错误:
Error:Strings should be wrapped in double quotes.[Code 17, Structure 20]
Error:Invalid characters found.[Code 18, Structure 20]
关于发生了什么的任何线索?
ios ×2
objective-c ×2
cocoa-touch ×1
iphone ×1
nsstring ×1
nsurlrequest ×1
urlencode ×1
utf-8 ×1
xcode ×1