iPhone应用开发之学习点滴


  本文标签:iPhone应用 异步队列

  iPhone应用开发中学习点滴是本文要介绍的内容,主要介绍了IPhone之NSBundle的使用、IPhone之ASINetworkQueue 异步队列、IPhone之获取Settings设置的内容,来看本文内容详解  。

  IPhone之NSBundle的使用

  NSBundle的对象可以获取应用程序安装目录的附件  。

  附件包括了,当前应用程序下,所有的文件  。(图片、属性列表等)

  获取XML文件

  1. NSString *filePath = [[NSBundle mainBundle] pathForResouse:@"re" ofType:@"xml"];  
  2. NSData *data = [[NSData alloc] initWithContentsOfFile:filePath];   

  获取属性列表

  1. NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:[[NSBundle mainBundle]   
  2. pathForResource:@"ViewControllers" ofType:@"plist"]]; 

  IPhone之ASINetworkQueue 异步队列

  使用NSOperationQueue(或ASINetWorkQueue,见下面示例)将给你对异步request更多的控制  。当使用队列的时候,只有确定数量的request可以同时运行  。如果你添加的request超过了队列的maxConcurrentOperationCount属性,request将在其他request运行完了之后运行  。

  注:ASINetworkQueue 类查看前面的IPhone之ASIHTTPRequest简介

  1.     //异步获取图片 ASINetworkQueue queue = [[ASINetworkQueue alloc] init];  
  2. for (ForumItem *item in itemList)  
  3.  {  
  4. //item.Image 图片的地址  
  5. if (item.Image)   
  6. {  
  7. ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:[NSURLURLWithString:item.Image]];  
  8. request.userInfo = [NSDictionary dictionaryWithObject:item.ImageforKey:@"Image"];  
  9. [request setDelegate:self];  
  10. [request setDidFinishSelector:@selector(requestDidFinished:)];  
  11. [queue addOperation:request];  
  12. }  
  13. }  
  14. [queue go]; 

  最后记的释放:queue

  IPhone之获取Settings设置

  IPhone中,可以用NSUserDefaults类读取用户设置  。NSUserDefaults在尖用程序中只有一个实例在运行  。获取代码如下:

  Key的值为 Root.plist中的Key值

  1. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];  
  2. [defaults objectForKey:@"username"];  
  3. [defaults objectForKey:@"password"];  
  4. [defaults objectForKey:@"protocol"];  
  5. [defaults objectForKey:@"warp"];  
  6. [[defaults objectForKey:@"warpFactor"] stringValue];  

  小结:iPhone应用开发之学习点滴的内容介绍完了,通过本文介绍的IPhone之NSBundle的使用、IPhone之ASINetworkQueue 异步队列IPhone之获取Settings设置的内容,希望在你学习中能帮助到你  。