forked from tanhaogg/THWebService
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTHWebService.h
More file actions
50 lines (39 loc) · 1.37 KB
/
THWebService.h
File metadata and controls
50 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// THWebService.h
// UserSystem
//
// Created by Hao Tan on 12-3-20.
// Copyright (c) 2012年 http://www.tanhao.me All rights reserved.
//
#import <Foundation/Foundation.h>
typedef void (^THWebServiceBlock) (NSURLResponse *response, NSError *error, NSData *data);
@protocol THWebServiceDelegate;
@interface THWebService : NSObject
{
id<THWebServiceDelegate> __unsafe_unretained _delegate;
NSURL *_url;
@protected
NSURLConnection *_con;
NSMutableData *_data;
}
@property (nonatomic, unsafe_unretained) id<THWebServiceDelegate> delegate;
@property (nonatomic, strong) NSURL *url;
@property (nonatomic, copy) THWebServiceBlock webServiceBlock;
- (void)stop;
- (BOOL)startAsynchronous;
- (NSData *)startSynchronous;
- (void)startWithHandler:(THWebServiceBlock)block;
+ (NSData *)dataWithUrl:(NSURL *)url;
+ (void)serviceWithUrl:(NSURL *)url handler:(THWebServiceBlock)block;
@end
@interface THWebService()
- (void)didReceiveResponse:(NSURLResponse *)response;
- (void)didReceiveData:(NSData *)aData;
- (void)didFailWithError:(NSError *)error;
- (void)didFinishLoading;
@end
@protocol THWebServiceDelegate<NSObject>
- (void)webServiceBegin:(THWebService *)webService;
- (void)webServiceFinish:(THWebService *)webService didReceiveData:(NSData *)data;
- (void)webServiceFail:(THWebService *)webService didFailWithError:(NSError *)error;
@end