urlHandler 0.1.1

urlHandler 0.1.1

测试已测试
语言语言 Obj-CObjective C
许可 MIT
发布最新版本2014年12月

Rahul Malik 维护。



  • 作者
  • Rahul Malik

Objective-C 中简单处理 NSURL 的方式

用法

在 AppDelegate 的 didFinishLaunchingWithOptions 中调用 initCache

[[UrlHandler sharedInstance] initCache];

基本 URL 请求。

[[UrlHandler sharedInstance] basicURL:@"http://google.com" :^(NSError *error, id returnObject) {
    if(error != (NSError*)[NSNull null] && ![returnObject isEqualToString:@"notReachable"]){
        NSLog(@"returnObject : %@",returnObject);
    }else{
        NSLog(@"error : %@",error);
    }
}];

带进度的文件下载。

[[UrlHandler sharedInstance] downloadFileWithURL:@"http://www.socialtalent.co/wp-content/uploads/blog-content/so-logo.png" withName:@"logo.png" progressBlock:^(float pre) {
    NSLog(@"progress :%f",pre);
} completionBlock:^(NSError *error, id returnObject) {
    NSLog(@"error : %@:%@",error,returnObject);
}];

带进度的多文件下载。

NSArray *array = @[@"http://wfiles.brothersoft.com/a/awesome-ice-block_178817-1920x1080.jpg",
                   @"http://www.hitswallpapers.com/wp-content/uploads/2014/07/awesome-city-wallpapers-1920x1080-2.jpg",
                   @"http://awesomewallpaper.files.wordpress.com/2011/09/splendorous1920x1080.jpg",
                   ];
[[UrlHandler sharedInstance] downloadListOfListWithArray:array progressBlock:^(float pre, int current) {
    NSLog(@"progress :%f:%d",pre,current);
} completionBlock:^(NSError *error, id returnObject, int currentObj) {
    NSLog(@"error : %@:%@:%d",error,returnObject,currentObj);
}];

表单请求。

NSDictionary *dic = @{
    @"name":@"awesome",
    @"email":@"[email protected]"
};
[[UrlHandler sharedInstance] basicFormURL:@"http://10.0.1.5/testPost.php" :@"POST" :dic :^(NSError *error, id returnObject) {
    if(error != (NSError*)[NSNull null] && ![returnObject isEqualToString:@"notReachable"]){
        NSLog(@"returnObject : %@",returnObject);
    }else{
        NSLog(@"error : %@",error);
    }
}];

带文件上传的表单请求。

NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"img.jpg"], 90);
NSDictionary *fileInfo = @{
    @"data":imageData,
    @"contentType":@"image/jpeg",
    @"fileName":@"image.jpeg",
    @"key":@"userfile"
};
dic = @{
                      @"comment":@"this is a comment",
                      @"region":@"[email protected]",
                      @"pincode":@"100000",
                      @"name":@"Rahul Emosewa",
                      @"phone":@"9821829923",
                      @"file":fileInfo
                      };
[[UrlHandler sharedInstance] multipleFormUrl:@"http://10.0.1.5/Afrimart_backEnd/post.php" :@"POST" postDictionary:dic progressBlock:^(float pre) {
    NSLog(@"progress :%f",pre);
} completionBlock:^(NSError *error, id returnObject) {
    NSLog(@"error : %@:%@",error,returnObject);
}];

作者

Rahul Malik, [email protected]

许可

urlHandler 捆绑于 MIT 许可下。查看 LICENSE 文件获取更多信息。