简体   繁体   English

可能? 单例Objective-C iOS的NSThread请求URL

[英]Possible? NSThread request URL by singleton Objective-C iOS

Situation. 情况。 XMLProxy Class is singleton. XMLProxy类为单例。 XMLRequest Class too. XMLRequest类也是如此。

Normally, when I want to request URL. 通常,当我要请求URL时。 Example : 范例:

XMLProxy *xmlProxy = [XMLProxy sharedInstance];
[xmlProxy tryGetDataWithParameter:example_parameter];

// Method "tryGetDataWithParameter" will call method "requestURL" from XMLRequest Class

// Assume that is [xmlRequest requestURL];

// and XMLProxy Class (XMLProxy delegate) will create xml parser for each "example_parameter" 
type to response xml data receive.

It's no problem. 没问题。

Question? 题? I want to create visual background process to request URL and I create AutoSending Class that is singleton. 我想创建视觉背景过程来请求URL,并创建单例的AutoSending类。

I want to use AutoSending Class to call method "tryGetDataWithParameter" (from XMLProxy class). 我想使用自动发送类来调用方法“ tryGetDataWithParameter”(来自XMLProxy类)。 Example to call : [autoSending start]; 调用示例:[自动发送开始];

-(void)start{ XMLProxy *xmlProxy = [XMLProxy sharedInstance]; -(void)start {XMLProxy * xmlProxy = [XMLProxy sharedInstance]; [xmlProxy tryetDataWithParameter:example_parameter]; [xmlProxy tryetDataWithParameter:example_parameter]; } }

Can I use NSThread to call statement "[autoSending start]"; 我可以使用NSThread调用语句“ [autoSending start]”吗? It is the result of a visual Background Process. 这是视觉背景过程的结果。

Rather than try to code all this up by yourself, why not use a library like AFNetworking which is built on top of NSURLConnection , NSOperation , and other standard IOS technologies. 与其尝试自己编写所有代码,不如使用AFNetworking之类的库,该库基于NSURLConnectionNSOperation和其他标准IOS技术构建。 You can then use NSOperationQueue to run your request on another thread. 然后,您可以使用NSOperationQueue在另一个线程上运行您的请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM