首页 > 其他 > 详细

plist文件读写

时间:2014-02-14 17:23:10      阅读:276      评论:0      收藏:0      [点我收藏+]

需求

1、用plist文件初始化一个数组,并输出数组中的元素。

2、分别用同步和异步从网上下载图片存到本地。使用异步的时候,显示下载进度。

bubuko.com,布布扣
#import "AppDelegate.h"
#define PATH1 @"http://h.hiphotos.baidu.com/image/w%3D2048/sign=4e4661fb3bdbb6fd255be2263d1caa18/42a98226cffc1e17951e59314890f603738de909.jpg"
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    //1关键-路径
    NSString *path = [[NSBundle mainBundle]pathForResource:@"abc" ofType:@"plist"];
    
    NSArray *arr = [NSArray arrayWithContentsOfFile:path];
    NSLog(@"arr = %@",arr);
    
    NSString *path2 = [[NSBundle mainBundle]pathForResource:@"Dictionary" ofType:@"plist"];
    NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path2];
    NSLog(@"dict = %@",dict);
    //2
    NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:PATH1] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120.0f];
    
    [NSURLConnection connectionWithRequest:req delegate:self];

    
    [self.window makeKeyAndVisible];
    return YES;
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
    mData = [[NSMutableData alloc]initWithLength:0];
    totalLenth = [response expectedContentLength];//
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [mData appendData:data];
    receivedLenth = mData.length;
    float progress = receivedLenth * 100.0 / totalLenth;//低精靠向高精
    NSLog(@"%lf%%",progress);
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [mData writeToFile:@"/Users/yf02/Desktop/Oc_12/123.png" atomically:YES];
}
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    
}
bubuko.com,布布扣

plist文件配置参考:http://blog.csdn.net/totogo2010/article/details/7634185

plist文件读写

原文:http://www.cnblogs.com/huen/p/3548587.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!