├── UploadFileTest ├── 1.jpg ├── 卡车.png ├── planet_mainBody.png ├── FD_NetWorking │ ├── NSString+URLEncode.h │ ├── PostDataConstructer.h │ ├── FDRequests.h │ ├── FDResponse.h │ ├── NSString+URLEncode.m │ ├── FDResponse.m │ ├── PostDataConstructer.m │ └── FDRequests.m ├── AppDelegate.h ├── main.m ├── ViewController.h ├── AppDelegate.m ├── WeiboAuthViewController.h ├── TFFileUploadManager.h ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── ViewController.m ├── WeiboAuthViewController.m └── TFFileUploadManager.m ├── README.md └── UploadFileTest.xcodeproj ├── project.xcworkspace ├── contents.xcworkspacedata └── xcuserdata │ └── shiwei.xcuserdatad │ └── UserInterfaceState.xcuserstate ├── xcuserdata └── shiwei.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── UploadFileTest.xcscheme └── project.pbxproj /UploadFileTest/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindCrt/UploadFileTest/HEAD/UploadFileTest/1.jpg -------------------------------------------------------------------------------- /UploadFileTest/卡车.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindCrt/UploadFileTest/HEAD/UploadFileTest/卡车.png -------------------------------------------------------------------------------- /UploadFileTest/planet_mainBody.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindCrt/UploadFileTest/HEAD/UploadFileTest/planet_mainBody.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UploadFileTest 2 | The project is an example that show how to upload a file to server by the form of 'multipart/form-data'.The detail introduction is here:http://www.jianshu.com/p/a0e3c77d3164 3 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/project.xcworkspace/xcuserdata/shiwei.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FindCrt/UploadFileTest/HEAD/UploadFileTest.xcodeproj/project.xcworkspace/xcuserdata/shiwei.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/NSString+URLEncode.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncode.h 3 | // coreDataExample_sinaWeibo 4 | // 5 | // Created by shiwei on 15/10/17. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (URLEncode) 12 | 13 | - (NSString *)urlEncode; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UploadFileTest/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /UploadFileTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/PostDataConstructer.h: -------------------------------------------------------------------------------- 1 | // 2 | // PostDataConstructer.h 3 | // coreDataExample_sinaWeibo 4 | // 5 | // Created by shiwei on 15/10/17. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface PostDataConstructer : NSObject 12 | 13 | +(NSData*)formDataWithParams:(NSDictionary*)params contentType:(NSString*)contentType; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /UploadFileTest/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | - (IBAction)postWeibo:(UIButton *)sender; 13 | - (IBAction)AuthWeibo:(UIBarButtonItem *)sender; 14 | 15 | @property (weak, nonatomic) IBOutlet UITextField *textField; 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /UploadFileTest/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 18 | 19 | return YES; 20 | } 21 | 22 | 23 | 24 | 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /UploadFileTest/WeiboAuthViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // WeiboAuthViewController.h 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #define weiboAppKey @"2582981980" 10 | #define client_id @"2582981980" 11 | #define redirect_uri @"https://www.baidu.com/" 12 | #define client_secret @"eb21a9799143f7c898f04a8571263074" 13 | 14 | #import 15 | 16 | @interface WeiboAuthViewController : UIViewController 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /UploadFileTest/TFFileUploadManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // TFFileUploadManager.h 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TFFileUploadManager : NSObject 12 | 13 | +(instancetype)shareInstance; 14 | 15 | -(void)uploadFileWithURL:(NSString*)urlString params:(NSDictionary*)params fileKey:(NSString*)fileKey filePath:(NSString*)filePath completeHander:(void(^)(NSURLResponse *response, NSData *data, NSError *connectionError))completeHander; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/xcuserdata/shiwei.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/xcuserdata/shiwei.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | UploadFileTest.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 89B9FB311C7959F600E8AA51 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/FDRequests.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDRequests.h 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "FDResponse.h" 11 | 12 | typedef void(^FDRequestsCallBack)(FDResponse* response); 13 | 14 | @interface FDRequests : NSObject 15 | 16 | +(void)useSession:(BOOL)use; 17 | 18 | +(void)getWithUrl:(NSString*)url params:(NSDictionary*)params callback:(FDRequestsCallBack)callback; 19 | 20 | //info's key contain method,url,cachePolicy,params,headers,cookies,files 21 | +(void)requestWithInfo:(NSDictionary*)info callback:(FDRequestsCallBack)callback; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/FDResponse.h: -------------------------------------------------------------------------------- 1 | // 2 | // FDResponse.h 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface FDResponse : NSObject 12 | 13 | @property (nonatomic, copy) NSURL* URL; 14 | 15 | @property (nonatomic, strong) NSMutableData* data; 16 | 17 | @property (nonatomic, assign) NSInteger statusCode; 18 | 19 | @property (nonatomic, strong) NSDictionary* headers; 20 | 21 | @property (nonatomic, assign) NSInteger dataLength; 22 | 23 | @property (nonatomic, strong) NSError* error; 24 | 25 | -(NSDictionary*)json; 26 | -(NSString*)text; 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/NSString+URLEncode.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+URLEncode.m 3 | // coreDataExample_sinaWeibo 4 | // 5 | // Created by shiwei on 15/10/17. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "NSString+URLEncode.h" 10 | 11 | @implementation NSString (URLEncode) 12 | 13 | - (NSString *)urlEncode { 14 | return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, 15 | (__bridge CFStringRef)self, NULL, 16 | (__bridge CFStringRef)@"!*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8); 17 | } 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /UploadFileTest/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/FDResponse.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDResponse.m 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "FDResponse.h" 10 | 11 | @interface FDResponse () 12 | 13 | @end 14 | 15 | @implementation FDResponse 16 | 17 | -(instancetype)init{ 18 | 19 | if (self = [super init]) { 20 | self.data = [[NSMutableData alloc]init]; 21 | } 22 | 23 | return self; 24 | } 25 | 26 | -(void)setError:(NSError *)error{ 27 | _error = error; 28 | 29 | if (_error) { 30 | self.data = nil; 31 | self.headers = nil; 32 | self.dataLength = 0; 33 | } 34 | } 35 | 36 | -(NSDictionary *)json{ 37 | NSError* error = nil; 38 | NSDictionary* jsonDic = [NSJSONSerialization JSONObjectWithData:self.data options:(NSJSONReadingAllowFragments) error:&error]; 39 | if (error) { 40 | NSLog(@"json transform error: %@",error); 41 | return nil; 42 | } 43 | return jsonDic; 44 | } 45 | 46 | -(NSString *)text{ 47 | return [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]; 48 | } 49 | 50 | @end 51 | -------------------------------------------------------------------------------- /UploadFileTest/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | NSAppTransportSecurity 40 | 41 | NSAllowsArbitraryLoads 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /UploadFileTest/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /UploadFileTest/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "WeiboAuthViewController.h" 11 | #import "TFFileUploadManager.h" 12 | 13 | @interface ViewController (){ 14 | NSString *_access_token; 15 | } 16 | 17 | @end 18 | 19 | @implementation ViewController 20 | 21 | - (void)viewDidLoad { 22 | [super viewDidLoad]; 23 | NSDictionary* weiboAuthInfo = [[NSUserDefaults standardUserDefaults]objectForKey:@"weiboAuthInfo"]; 24 | _access_token = [weiboAuthInfo objectForKey:@"access_token"]; 25 | 26 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(weiboAuthSuccess:) name:@"weiboAuthSuccess" object:nil]; 27 | } 28 | 29 | -(void)weiboAuthSuccess:(NSNotification*)notification{ 30 | NSDictionary* weiboAuthInfo = [[NSUserDefaults standardUserDefaults]objectForKey:@"weiboAuthInfo"]; 31 | _access_token = [weiboAuthInfo objectForKey:@"access_token"]; 32 | } 33 | 34 | - (IBAction)postWeibo:(UIButton *)sender { 35 | if (!_access_token) { 36 | NSLog(@"还未授权"); 37 | return; 38 | } 39 | 40 | NSString* url = @"https://upload.api.weibo.com/2/statuses/upload.json"; 41 | NSString* content = _textField.text; 42 | 43 | NSString* filepath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"jpg"]; 44 | 45 | NSDictionary* param = @{@"access_token":_access_token,@"status":content,@"source":@"2582981980"}; 46 | 47 | [[TFFileUploadManager shareInstance] uploadFileWithURL:url params:param fileKey:@"pic" filePath:filepath completeHander:^(NSURLResponse *response, NSData *data, NSError *connectionError) { 48 | 49 | if (connectionError) { 50 | NSLog(@"请求出错 %@",connectionError); 51 | }else{ 52 | NSLog(@"请求返回:\n%@",response); 53 | } 54 | }]; 55 | } 56 | 57 | - (IBAction)AuthWeibo:(UIBarButtonItem *)sender { 58 | WeiboAuthViewController *weiboAuthVC = [[WeiboAuthViewController alloc]init]; 59 | [self.navigationController pushViewController:weiboAuthVC animated:YES]; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/PostDataConstructer.m: -------------------------------------------------------------------------------- 1 | // 2 | // PostDataConstructer.m 3 | // coreDataExample_sinaWeibo 4 | // 5 | // Created by shiwei on 15/10/17. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "PostDataConstructer.h" 10 | #import "NSString+URLEncode.h" 11 | 12 | @implementation PostDataConstructer 13 | 14 | +(NSData*)formDataWithParams:(NSDictionary*)params contentType:(NSString *)contentType{ 15 | 16 | NSMutableData* postData = [NSMutableData data]; 17 | 18 | if ([contentType hasPrefix:@"multipart/form-data"]) { 19 | 20 | NSRange range = [contentType rangeOfString:@"="]; 21 | NSAssert(range.location != NSNotFound, @"Content-Type缺少doundary"); 22 | 23 | NSString* boundary = [contentType substringFromIndex:range.location+1]; 24 | NSData* boundaryData = [[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]; 25 | 26 | 27 | [postData appendData:boundaryData]; 28 | 29 | NSArray* allKeys = params.allKeys; 30 | for (NSString* key in params.allKeys) { 31 | [postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n",key] dataUsingEncoding:NSUTF8StringEncoding]]; 32 | 33 | id value = [params objectForKey:key]; 34 | if ([value isKindOfClass:[NSData class]]) { 35 | [postData appendData:value]; 36 | }else{ 37 | [postData appendData:[value dataUsingEncoding:NSUTF8StringEncoding]]; 38 | } 39 | 40 | if (key == allKeys.lastObject) { 41 | [postData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 42 | }else{ 43 | [postData appendData:boundaryData]; 44 | } 45 | 46 | } 47 | }else{ 48 | 49 | NSMutableString* postString = [NSMutableString string]; 50 | for (NSString* key in params) { 51 | 52 | NSString* value = [NSString stringWithFormat:@"%@",[params valueForKey:key]]; 53 | [postString appendFormat:@"%@=%@",key,[value urlEncode]]; 54 | if (key != params.allKeys.lastObject) { 55 | [postString appendString:@"&"]; 56 | } 57 | } 58 | postData = (NSMutableData*)[postString dataUsingEncoding:NSUTF8StringEncoding]; 59 | } 60 | 61 | 62 | return postData; 63 | } 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /UploadFileTest/WeiboAuthViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // WeiboAuthViewController.m 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "WeiboAuthViewController.h" 10 | #import "FDRequests.h" 11 | 12 | @interface WeiboAuthViewController () 13 | @property (weak, nonatomic) IBOutlet UIWebView *webView; 14 | 15 | @end 16 | 17 | @implementation WeiboAuthViewController 18 | 19 | - (void)viewDidLoad { 20 | [super viewDidLoad]; 21 | 22 | NSString* urlString = [NSString stringWithFormat:@"https://api.weibo.com/oauth2/authorize?client_id=%@&response_type=code&redirect_uri=%@",client_id,redirect_uri]; 23 | NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]]; 24 | [self.webView loadRequest:request]; 25 | } 26 | 27 | #pragma mark - webView delegate 28 | 29 | - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ 30 | 31 | //授权成功,跳转,这是就可以退出去了;返回的参数code携带在跳转的url里 32 | if ([request.URL.absoluteString hasPrefix:redirect_uri]) { 33 | NSString* query = request.URL.query; 34 | NSString* code = [[query componentsSeparatedByString:@"="]lastObject]; 35 | 36 | [self obtainAccessTokenWithCode:code]; 37 | return NO; 38 | } 39 | return YES; 40 | } 41 | 42 | -(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{ 43 | NSLog(@"webView load error: %@",error); 44 | } 45 | 46 | -(void)obtainAccessTokenWithCode:(NSString*)code{ 47 | 48 | NSDictionary* weiboAuthInfo = [[NSUserDefaults standardUserDefaults]objectForKey:@"weiboAuthInfo"]; 49 | 50 | NSDictionary* params = @{ 51 | @"client_id":client_id, 52 | @"client_secret":client_secret, 53 | @"grant_type":@"authorization_code", 54 | @"code":code, 55 | @"redirect_uri":redirect_uri 56 | }; 57 | NSDictionary* info = @{ 58 | @"method":@"POST", 59 | @"url":@"https://api.weibo.com/oauth2/access_token", 60 | @"params":params 61 | }; 62 | [FDRequests requestWithInfo:info callback:^(FDResponse *response) { 63 | if (response.error) { 64 | NSLog(@"%@",response.error); 65 | return ; 66 | } 67 | //access_token,uid,expires_in(授权剩余秒数) 68 | NSDictionary* datas = response.json; 69 | NSMutableDictionary* temp = weiboAuthInfo.mutableCopy; 70 | [temp addEntriesFromDictionary:datas]; 71 | 72 | [[NSUserDefaults standardUserDefaults]setObject:temp forKey:@"weiboAuthInfo"]; 73 | 74 | dispatch_async(dispatch_get_main_queue(), ^{ 75 | [self.navigationController popViewControllerAnimated:YES]; 76 | [[NSNotificationCenter defaultCenter]postNotificationName:@"weiboAuthSuccess" object:nil]; 77 | }); 78 | 79 | }]; 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/xcuserdata/shiwei.xcuserdatad/xcschemes/UploadFileTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /UploadFileTest/TFFileUploadManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // TFFileUploadManager.m 3 | // UploadFileTest 4 | // 5 | // Created by shiwei on 16/2/21. 6 | // Copyright © 2016年 shiwei. All rights reserved. 7 | // 8 | 9 | #import "TFFileUploadManager.h" 10 | #import 11 | 12 | @implementation TFFileUploadManager{ 13 | NSMutableURLRequest *request; 14 | NSOperationQueue *queue; 15 | NSURLConnection *_connection; 16 | NSMutableData *_reveivedData; 17 | } 18 | 19 | +(instancetype)shareInstance{ 20 | static TFFileUploadManager *manager = nil; 21 | static dispatch_once_t onceToken; 22 | dispatch_once(&onceToken, ^{ 23 | manager = [[TFFileUploadManager alloc]init]; 24 | }); 25 | 26 | return manager; 27 | } 28 | 29 | -(void)uploadFileWithURL:(NSString *)urlString params:(NSDictionary *)params fileKey:(NSString *)fileKey filePath:(NSString *)filePath completeHander:(void (^)(NSURLResponse *, NSData *, NSError *))completeHander{ 30 | 31 | NSURL *URL = [[NSURL alloc]initWithString:urlString]; 32 | request = [[NSMutableURLRequest alloc]initWithURL:URL cachePolicy:(NSURLRequestUseProtocolCachePolicy) timeoutInterval:30]; 33 | NSString *boundary = @"wfWiEWrgEFA9A78512weF7106A"; 34 | 35 | NSData *fileData = [NSData dataWithContentsOfFile:filePath]; 36 | 37 | request.HTTPMethod = @"POST"; 38 | request.allHTTPHeaderFields = @{ 39 | @"Content-Type":[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] 40 | }; 41 | 42 | //multipart/form-data格式按照构建上传数据 43 | NSMutableData *postData = [[NSMutableData alloc]init]; 44 | for (NSString *key in params) { 45 | NSString *pair = [NSString stringWithFormat:@"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n",boundary,key]; 46 | [postData appendData:[pair dataUsingEncoding:NSUTF8StringEncoding]]; 47 | 48 | id value = [params objectForKey:key]; 49 | if ([value isKindOfClass:[NSString class]]) { 50 | [postData appendData:[value dataUsingEncoding:NSUTF8StringEncoding]]; 51 | }else if ([value isKindOfClass:[NSData class]]){ 52 | [postData appendData:value]; 53 | } 54 | [postData appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]]; 55 | } 56 | 57 | //文件部分 58 | NSString *filename = [filePath lastPathComponent]; 59 | NSString *contentType = AFContentTypeForPathExtension([filePath pathExtension]); 60 | 61 | NSString *filePair = [NSString stringWithFormat:@"--%@\r\nContent-Disposition: form-data; name=\"%@\"; filename=\"%@\";Content-Type=%@\r\n\r\n",boundary,fileKey,filename,contentType]; 62 | [postData appendData:[filePair dataUsingEncoding:NSUTF8StringEncoding]]; 63 | 64 | //[postData appendData:[@"测试文件数据" dataUsingEncoding:NSUTF8StringEncoding]]; 65 | [postData appendData:fileData]; //加入文件的数据 66 | 67 | [postData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; 68 | request.HTTPBody = postData; 69 | [request setValue:[NSString stringWithFormat:@"%lu",(unsigned long)postData.length] forHTTPHeaderField:@"Content-Length"]; 70 | 71 | _connection = [[NSURLConnection alloc]initWithRequest:request delegate:self]; 72 | [_connection start]; 73 | } 74 | 75 | #pragma mark - connection delegate 76 | 77 | -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 78 | NSLog(@"reveive Response:\n%@",response); 79 | } 80 | 81 | -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 82 | if (!_reveivedData) { 83 | _reveivedData = [[NSMutableData alloc]init]; 84 | } 85 | 86 | [_reveivedData appendData:data]; 87 | } 88 | 89 | -(void)connectionDidFinishLoading:(NSURLConnection *)connection{ 90 | NSLog(@"received Data:\n%@",[[NSString alloc] initWithData:_reveivedData encoding:NSUTF8StringEncoding]); 91 | } 92 | 93 | -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ 94 | NSLog(@"fail connect:\n%@",error); 95 | } 96 | 97 | 98 | static inline NSString * AFContentTypeForPathExtension(NSString *extension) { 99 | #ifdef __UTTYPE__ 100 | NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)extension, NULL); 101 | NSString *contentType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType); 102 | if (!contentType) { 103 | return @"application/octet-stream"; 104 | } else { 105 | return contentType; 106 | } 107 | #else 108 | #pragma unused (extension) 109 | return @"application/octet-stream"; 110 | #endif 111 | } 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /UploadFileTest/FD_NetWorking/FDRequests.m: -------------------------------------------------------------------------------- 1 | // 2 | // FDRequests.m 3 | // Networking 4 | // 5 | // Created by shiwei on 15/10/5. 6 | // Copyright © 2015年 shiwei. All rights reserved. 7 | // 8 | 9 | 10 | #import "FDRequests.h" 11 | #import "PostDataConstructer.h" 12 | #import "NSString+URLEncode.h" 13 | 14 | @interface FDRequests () 15 | 16 | @property (nonatomic, copy) NSString* method; 17 | 18 | @property (nonatomic, strong) NSMutableURLRequest* request; 19 | @property (nonatomic, strong) NSURLConnection* connection; 20 | 21 | @property (nonatomic, copy) FDRequestsCallBack callback; 22 | 23 | @property (nonatomic, strong) FDResponse* response; 24 | 25 | @end 26 | 27 | static BOOL _userSession = NO; 28 | @implementation FDRequests 29 | 30 | +(void)useSession:(BOOL)use{ 31 | _userSession = use; 32 | } 33 | 34 | +(void)getWithUrl:(NSString *)url params:(NSDictionary *)params callback:(FDRequestsCallBack)callback{ 35 | NSDictionary* requestInfo = @{ 36 | @"url":url, 37 | @"params":params, 38 | @"method":@"GET" 39 | }; 40 | [self requestWithInfo:requestInfo callback:callback]; 41 | } 42 | 43 | +(void)requestWithInfo:(NSDictionary *)info callback:(FDRequestsCallBack)callback{ 44 | FDRequests* newRequest = [[FDRequests alloc]initWithRequestInfo:info]; 45 | newRequest.callback = callback; 46 | [newRequest start]; 47 | } 48 | 49 | -(instancetype)initWithRequestInfo:(NSDictionary*)RequestInfo{ 50 | if (self = [super init]) { 51 | 52 | self.method = [RequestInfo valueForKey:@"method"]?:@"GET"; 53 | 54 | NSString* urlString = [RequestInfo valueForKey:@"url"]; 55 | NSURL* URL = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 56 | NSURLRequestCachePolicy cachePolicy = [[RequestInfo valueForKey:@"cachePolicy"] integerValue]; 57 | NSTimeInterval timeoutInterval = [[RequestInfo valueForKey:@"timeout"] integerValue]; 58 | 59 | self.request = [NSMutableURLRequest requestWithURL:URL cachePolicy:cachePolicy timeoutInterval:timeoutInterval]; 60 | self.request.HTTPMethod = self.method; 61 | NSDictionary* headers =[RequestInfo valueForKey:@"headers"]; 62 | if (headers) { 63 | self.request.allHTTPHeaderFields = headers; 64 | 65 | } 66 | 67 | NSDictionary* params = [RequestInfo valueForKey:@"params"]; 68 | 69 | 70 | if ([self.method isEqualToString:@"GET"]) { 71 | NSMutableString* query = [NSMutableString string]; 72 | for (NSString* key in params) { 73 | 74 | NSString* value = [NSString stringWithFormat:@"%@",[params valueForKey:key]]; 75 | [query appendFormat:@"%@=%@",key,[value urlEncode]]; 76 | if (key != params.allKeys.lastObject) { 77 | [query appendString:@"&"]; 78 | } 79 | } 80 | urlString = [urlString stringByAppendingFormat:@"?%@",query]; 81 | self.request.URL = [NSURL URLWithString:urlString]; 82 | 83 | }else if ([self.method isEqualToString:@"POST"]){ 84 | 85 | NSString* contentType = [headers objectForKey:@"Content-Type"]; 86 | NSData* body = [PostDataConstructer formDataWithParams:params contentType:contentType]; 87 | 88 | self.request.HTTPBody = body; 89 | } 90 | 91 | } 92 | 93 | return self; 94 | } 95 | 96 | -(void)start{ 97 | self.response = [[FDResponse alloc]init]; 98 | 99 | if (_userSession) { 100 | 101 | NSURLSession* session = [NSURLSession sharedSession]; 102 | NSURLSessionDataTask* newTask = [session dataTaskWithRequest:self.request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { 103 | 104 | if (error) { 105 | 106 | [self finishWithSuccess:NO error:error]; 107 | return; 108 | } 109 | self.response.data = (NSMutableData*)data; 110 | if ([response isKindOfClass:[NSHTTPURLResponse class]]) { 111 | self.response.headers = ((NSHTTPURLResponse*)response).allHeaderFields; 112 | self.response.dataLength = response.expectedContentLength; 113 | } 114 | [self finishWithSuccess:YES error:nil]; 115 | }]; 116 | 117 | [newTask resume]; 118 | 119 | }else{ 120 | self.connection = [NSURLConnection connectionWithRequest:self.request delegate:self]; 121 | [self.connection start]; 122 | } 123 | 124 | } 125 | 126 | -(void)finishWithSuccess:(BOOL)success error:(NSError*)error{ 127 | if (!success) { 128 | self.response.error = error; 129 | } 130 | #if DEBUG 131 | //NSLog(@"%@",self.response.text); 132 | #endif 133 | self.callback(self.response); 134 | } 135 | 136 | +(FDResponse *)syncRequestWithUrl:(NSString *)rul params:(NSDictionary *)params{ 137 | if (params == nil) { 138 | params = @{}; 139 | } 140 | NSDictionary* requestInfo = @{ 141 | @"url":rul, 142 | @"params":params, 143 | @"method":@"GET" 144 | }; 145 | return [self syncRequestWithInfo:requestInfo]; 146 | } 147 | 148 | +(FDResponse *)syncRequestWithInfo:(NSDictionary *)info{ 149 | FDRequests* newRequest = [[FDRequests alloc]initWithRequestInfo:info]; 150 | 151 | NSURLResponse* response = nil; 152 | NSError* error = nil; 153 | NSData* data = [NSURLConnection sendSynchronousRequest:newRequest.request returningResponse:&response error:&error]; 154 | if (error) { 155 | NSLog(@"sync request error:%@",error); 156 | return nil; 157 | } 158 | FDResponse* myResponse = [[FDResponse alloc]init]; 159 | myResponse.data = (NSMutableData*)data; 160 | myResponse.URL = newRequest.request.URL; 161 | return myResponse; 162 | } 163 | 164 | #pragma mark - connection data delegate 165 | 166 | -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{ 167 | if ([response isKindOfClass:[NSHTTPURLResponse class]]) { 168 | self.response.headers = ((NSHTTPURLResponse*)response).allHeaderFields; 169 | self.response.dataLength = response.expectedContentLength; 170 | self.response.statusCode = ((NSHTTPURLResponse*)response).statusCode; 171 | } 172 | self.response.URL = response.URL; 173 | 174 | } 175 | 176 | -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{ 177 | [self.response.data appendData:data]; 178 | } 179 | 180 | -(void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{ 181 | 182 | } 183 | 184 | - (nullable NSCachedURLResponse *)connection:(NSURLConnection *)connection willCacheResponse:(NSCachedURLResponse *)cachedResponse{ 185 | return cachedResponse; 186 | } 187 | 188 | - (void)connectionDidFinishLoading:(NSURLConnection *)connection{ 189 | [self finishWithSuccess:YES error:nil]; 190 | } 191 | 192 | -(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{ 193 | [self finishWithSuccess:NO error:error]; 194 | } 195 | 196 | #pragma mark - upload 197 | 198 | +(void)uploadFileWithInfo:(NSDictionary *)info filePath:(NSString *)filePath callback:(FDRequestsCallBack)callback{ 199 | 200 | FDRequests* request = [[FDRequests alloc]initWithRequestInfo:info]; 201 | request.callback = callback; 202 | [request start]; 203 | 204 | } 205 | 206 | @end 207 | -------------------------------------------------------------------------------- /UploadFileTest/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /UploadFileTest.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 89B650021C795FA300450087 /* 1.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 89B650011C795FA300450087 /* 1.jpg */; }; 11 | 89B650051C79600300450087 /* WeiboAuthViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B650041C79600300450087 /* WeiboAuthViewController.m */; }; 12 | 89B9FB371C7959F600E8AA51 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B9FB361C7959F600E8AA51 /* main.m */; }; 13 | 89B9FB3A1C7959F600E8AA51 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B9FB391C7959F600E8AA51 /* AppDelegate.m */; }; 14 | 89B9FB3D1C7959F600E8AA51 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 89B9FB3C1C7959F600E8AA51 /* ViewController.m */; }; 15 | 89B9FB401C7959F600E8AA51 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 89B9FB3E1C7959F600E8AA51 /* Main.storyboard */; }; 16 | 89B9FB421C7959F600E8AA51 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 89B9FB411C7959F600E8AA51 /* Assets.xcassets */; }; 17 | 89B9FB451C7959F600E8AA51 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 89B9FB431C7959F600E8AA51 /* LaunchScreen.storyboard */; }; 18 | 89F7948C1C79646C001B199E /* TFFileUploadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 89F7948B1C79646C001B199E /* TFFileUploadManager.m */; }; 19 | 89F7948E1C798F42001B199E /* planet_mainBody.png in Resources */ = {isa = PBXBuildFile; fileRef = 89F7948D1C798F42001B199E /* planet_mainBody.png */; }; 20 | 89F794981C79968C001B199E /* FDRequests.m in Sources */ = {isa = PBXBuildFile; fileRef = 89F794911C79968C001B199E /* FDRequests.m */; }; 21 | 89F794991C79968C001B199E /* FDResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 89F794931C79968C001B199E /* FDResponse.m */; }; 22 | 89F7949A1C79968C001B199E /* NSString+URLEncode.m in Sources */ = {isa = PBXBuildFile; fileRef = 89F794951C79968C001B199E /* NSString+URLEncode.m */; }; 23 | 89F7949B1C79968C001B199E /* PostDataConstructer.m in Sources */ = {isa = PBXBuildFile; fileRef = 89F794971C79968C001B199E /* PostDataConstructer.m */; }; 24 | 89F7949D1C799F1B001B199E /* 卡车.png in Resources */ = {isa = PBXBuildFile; fileRef = 89F7949C1C799F1B001B199E /* 卡车.png */; }; 25 | 89F7949F1C7A0A39001B199E /* MobileCoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 89F7949E1C7A0A39001B199E /* MobileCoreServices.framework */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXFileReference section */ 29 | 89B650011C795FA300450087 /* 1.jpg */ = {isa = PBXFileReference; lastKnownFileType = image.jpeg; path = 1.jpg; sourceTree = ""; }; 30 | 89B650031C79600300450087 /* WeiboAuthViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WeiboAuthViewController.h; sourceTree = ""; }; 31 | 89B650041C79600300450087 /* WeiboAuthViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WeiboAuthViewController.m; sourceTree = ""; }; 32 | 89B9FB321C7959F600E8AA51 /* UploadFileTest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = UploadFileTest.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | 89B9FB361C7959F600E8AA51 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | 89B9FB381C7959F600E8AA51 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 35 | 89B9FB391C7959F600E8AA51 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 36 | 89B9FB3B1C7959F600E8AA51 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 37 | 89B9FB3C1C7959F600E8AA51 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 38 | 89B9FB3F1C7959F600E8AA51 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 39 | 89B9FB411C7959F600E8AA51 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 40 | 89B9FB441C7959F600E8AA51 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 41 | 89B9FB461C7959F600E8AA51 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 42 | 89F7948A1C79646C001B199E /* TFFileUploadManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TFFileUploadManager.h; sourceTree = ""; }; 43 | 89F7948B1C79646C001B199E /* TFFileUploadManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TFFileUploadManager.m; sourceTree = ""; }; 44 | 89F7948D1C798F42001B199E /* planet_mainBody.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = planet_mainBody.png; sourceTree = ""; }; 45 | 89F794901C79968C001B199E /* FDRequests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDRequests.h; sourceTree = ""; }; 46 | 89F794911C79968C001B199E /* FDRequests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDRequests.m; sourceTree = ""; }; 47 | 89F794921C79968C001B199E /* FDResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FDResponse.h; sourceTree = ""; }; 48 | 89F794931C79968C001B199E /* FDResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FDResponse.m; sourceTree = ""; }; 49 | 89F794941C79968C001B199E /* NSString+URLEncode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+URLEncode.h"; sourceTree = ""; }; 50 | 89F794951C79968C001B199E /* NSString+URLEncode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+URLEncode.m"; sourceTree = ""; }; 51 | 89F794961C79968C001B199E /* PostDataConstructer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PostDataConstructer.h; sourceTree = ""; }; 52 | 89F794971C79968C001B199E /* PostDataConstructer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PostDataConstructer.m; sourceTree = ""; }; 53 | 89F7949C1C799F1B001B199E /* 卡车.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "卡车.png"; sourceTree = ""; }; 54 | 89F7949E1C7A0A39001B199E /* MobileCoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MobileCoreServices.framework; path = System/Library/Frameworks/MobileCoreServices.framework; sourceTree = SDKROOT; }; 55 | /* End PBXFileReference section */ 56 | 57 | /* Begin PBXFrameworksBuildPhase section */ 58 | 89B9FB2F1C7959F600E8AA51 /* Frameworks */ = { 59 | isa = PBXFrameworksBuildPhase; 60 | buildActionMask = 2147483647; 61 | files = ( 62 | 89F7949F1C7A0A39001B199E /* MobileCoreServices.framework in Frameworks */, 63 | ); 64 | runOnlyForDeploymentPostprocessing = 0; 65 | }; 66 | /* End PBXFrameworksBuildPhase section */ 67 | 68 | /* Begin PBXGroup section */ 69 | 89B9FB291C7959F600E8AA51 = { 70 | isa = PBXGroup; 71 | children = ( 72 | 89F7949E1C7A0A39001B199E /* MobileCoreServices.framework */, 73 | 89B9FB341C7959F600E8AA51 /* UploadFileTest */, 74 | 89B9FB331C7959F600E8AA51 /* Products */, 75 | ); 76 | sourceTree = ""; 77 | }; 78 | 89B9FB331C7959F600E8AA51 /* Products */ = { 79 | isa = PBXGroup; 80 | children = ( 81 | 89B9FB321C7959F600E8AA51 /* UploadFileTest.app */, 82 | ); 83 | name = Products; 84 | sourceTree = ""; 85 | }; 86 | 89B9FB341C7959F600E8AA51 /* UploadFileTest */ = { 87 | isa = PBXGroup; 88 | children = ( 89 | 89B9FB381C7959F600E8AA51 /* AppDelegate.h */, 90 | 89B9FB391C7959F600E8AA51 /* AppDelegate.m */, 91 | 89B9FB3B1C7959F600E8AA51 /* ViewController.h */, 92 | 89B9FB3C1C7959F600E8AA51 /* ViewController.m */, 93 | 89F7948A1C79646C001B199E /* TFFileUploadManager.h */, 94 | 89F7948B1C79646C001B199E /* TFFileUploadManager.m */, 95 | 89B650031C79600300450087 /* WeiboAuthViewController.h */, 96 | 89B650041C79600300450087 /* WeiboAuthViewController.m */, 97 | 89F7948F1C79968C001B199E /* FD_NetWorking */, 98 | 89B9FB3E1C7959F600E8AA51 /* Main.storyboard */, 99 | 89B650011C795FA300450087 /* 1.jpg */, 100 | 89B9FB411C7959F600E8AA51 /* Assets.xcassets */, 101 | 89B9FB431C7959F600E8AA51 /* LaunchScreen.storyboard */, 102 | 89B9FB461C7959F600E8AA51 /* Info.plist */, 103 | 89B9FB351C7959F600E8AA51 /* Supporting Files */, 104 | 89F7948D1C798F42001B199E /* planet_mainBody.png */, 105 | 89F7949C1C799F1B001B199E /* 卡车.png */, 106 | ); 107 | path = UploadFileTest; 108 | sourceTree = ""; 109 | }; 110 | 89B9FB351C7959F600E8AA51 /* Supporting Files */ = { 111 | isa = PBXGroup; 112 | children = ( 113 | 89B9FB361C7959F600E8AA51 /* main.m */, 114 | ); 115 | name = "Supporting Files"; 116 | sourceTree = ""; 117 | }; 118 | 89F7948F1C79968C001B199E /* FD_NetWorking */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | 89F794901C79968C001B199E /* FDRequests.h */, 122 | 89F794911C79968C001B199E /* FDRequests.m */, 123 | 89F794921C79968C001B199E /* FDResponse.h */, 124 | 89F794931C79968C001B199E /* FDResponse.m */, 125 | 89F794941C79968C001B199E /* NSString+URLEncode.h */, 126 | 89F794951C79968C001B199E /* NSString+URLEncode.m */, 127 | 89F794961C79968C001B199E /* PostDataConstructer.h */, 128 | 89F794971C79968C001B199E /* PostDataConstructer.m */, 129 | ); 130 | path = FD_NetWorking; 131 | sourceTree = ""; 132 | }; 133 | /* End PBXGroup section */ 134 | 135 | /* Begin PBXNativeTarget section */ 136 | 89B9FB311C7959F600E8AA51 /* UploadFileTest */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = 89B9FB491C7959F600E8AA51 /* Build configuration list for PBXNativeTarget "UploadFileTest" */; 139 | buildPhases = ( 140 | 89B9FB2E1C7959F600E8AA51 /* Sources */, 141 | 89B9FB2F1C7959F600E8AA51 /* Frameworks */, 142 | 89B9FB301C7959F600E8AA51 /* Resources */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | ); 148 | name = UploadFileTest; 149 | productName = UploadFileTest; 150 | productReference = 89B9FB321C7959F600E8AA51 /* UploadFileTest.app */; 151 | productType = "com.apple.product-type.application"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | 89B9FB2A1C7959F600E8AA51 /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastUpgradeCheck = 0710; 160 | ORGANIZATIONNAME = shiwei; 161 | TargetAttributes = { 162 | 89B9FB311C7959F600E8AA51 = { 163 | CreatedOnToolsVersion = 7.1.1; 164 | }; 165 | }; 166 | }; 167 | buildConfigurationList = 89B9FB2D1C7959F600E8AA51 /* Build configuration list for PBXProject "UploadFileTest" */; 168 | compatibilityVersion = "Xcode 3.2"; 169 | developmentRegion = English; 170 | hasScannedForEncodings = 0; 171 | knownRegions = ( 172 | en, 173 | Base, 174 | ); 175 | mainGroup = 89B9FB291C7959F600E8AA51; 176 | productRefGroup = 89B9FB331C7959F600E8AA51 /* Products */; 177 | projectDirPath = ""; 178 | projectRoot = ""; 179 | targets = ( 180 | 89B9FB311C7959F600E8AA51 /* UploadFileTest */, 181 | ); 182 | }; 183 | /* End PBXProject section */ 184 | 185 | /* Begin PBXResourcesBuildPhase section */ 186 | 89B9FB301C7959F600E8AA51 /* Resources */ = { 187 | isa = PBXResourcesBuildPhase; 188 | buildActionMask = 2147483647; 189 | files = ( 190 | 89B9FB451C7959F600E8AA51 /* LaunchScreen.storyboard in Resources */, 191 | 89B650021C795FA300450087 /* 1.jpg in Resources */, 192 | 89F7949D1C799F1B001B199E /* 卡车.png in Resources */, 193 | 89B9FB421C7959F600E8AA51 /* Assets.xcassets in Resources */, 194 | 89F7948E1C798F42001B199E /* planet_mainBody.png in Resources */, 195 | 89B9FB401C7959F600E8AA51 /* Main.storyboard in Resources */, 196 | ); 197 | runOnlyForDeploymentPostprocessing = 0; 198 | }; 199 | /* End PBXResourcesBuildPhase section */ 200 | 201 | /* Begin PBXSourcesBuildPhase section */ 202 | 89B9FB2E1C7959F600E8AA51 /* Sources */ = { 203 | isa = PBXSourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 89B9FB3D1C7959F600E8AA51 /* ViewController.m in Sources */, 207 | 89F7949B1C79968C001B199E /* PostDataConstructer.m in Sources */, 208 | 89B9FB3A1C7959F600E8AA51 /* AppDelegate.m in Sources */, 209 | 89B9FB371C7959F600E8AA51 /* main.m in Sources */, 210 | 89F7949A1C79968C001B199E /* NSString+URLEncode.m in Sources */, 211 | 89B650051C79600300450087 /* WeiboAuthViewController.m in Sources */, 212 | 89F7948C1C79646C001B199E /* TFFileUploadManager.m in Sources */, 213 | 89F794991C79968C001B199E /* FDResponse.m in Sources */, 214 | 89F794981C79968C001B199E /* FDRequests.m in Sources */, 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXSourcesBuildPhase section */ 219 | 220 | /* Begin PBXVariantGroup section */ 221 | 89B9FB3E1C7959F600E8AA51 /* Main.storyboard */ = { 222 | isa = PBXVariantGroup; 223 | children = ( 224 | 89B9FB3F1C7959F600E8AA51 /* Base */, 225 | ); 226 | name = Main.storyboard; 227 | sourceTree = ""; 228 | }; 229 | 89B9FB431C7959F600E8AA51 /* LaunchScreen.storyboard */ = { 230 | isa = PBXVariantGroup; 231 | children = ( 232 | 89B9FB441C7959F600E8AA51 /* Base */, 233 | ); 234 | name = LaunchScreen.storyboard; 235 | sourceTree = ""; 236 | }; 237 | /* End PBXVariantGroup section */ 238 | 239 | /* Begin XCBuildConfiguration section */ 240 | 89B9FB471C7959F600E8AA51 /* Debug */ = { 241 | isa = XCBuildConfiguration; 242 | buildSettings = { 243 | ALWAYS_SEARCH_USER_PATHS = NO; 244 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 245 | CLANG_CXX_LIBRARY = "libc++"; 246 | CLANG_ENABLE_MODULES = YES; 247 | CLANG_ENABLE_OBJC_ARC = YES; 248 | CLANG_WARN_BOOL_CONVERSION = YES; 249 | CLANG_WARN_CONSTANT_CONVERSION = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_EMPTY_BODY = YES; 252 | CLANG_WARN_ENUM_CONVERSION = YES; 253 | CLANG_WARN_INT_CONVERSION = YES; 254 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 255 | CLANG_WARN_UNREACHABLE_CODE = YES; 256 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 257 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 258 | COPY_PHASE_STRIP = NO; 259 | DEBUG_INFORMATION_FORMAT = dwarf; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | ENABLE_TESTABILITY = YES; 262 | GCC_C_LANGUAGE_STANDARD = gnu99; 263 | GCC_DYNAMIC_NO_PIC = NO; 264 | GCC_NO_COMMON_BLOCKS = YES; 265 | GCC_OPTIMIZATION_LEVEL = 0; 266 | GCC_PREPROCESSOR_DEFINITIONS = ( 267 | "DEBUG=1", 268 | "$(inherited)", 269 | ); 270 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 271 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 272 | GCC_WARN_UNDECLARED_SELECTOR = YES; 273 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 274 | GCC_WARN_UNUSED_FUNCTION = YES; 275 | GCC_WARN_UNUSED_VARIABLE = YES; 276 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 277 | MTL_ENABLE_DEBUG_INFO = YES; 278 | ONLY_ACTIVE_ARCH = YES; 279 | SDKROOT = iphoneos; 280 | }; 281 | name = Debug; 282 | }; 283 | 89B9FB481C7959F600E8AA51 /* Release */ = { 284 | isa = XCBuildConfiguration; 285 | buildSettings = { 286 | ALWAYS_SEARCH_USER_PATHS = NO; 287 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 288 | CLANG_CXX_LIBRARY = "libc++"; 289 | CLANG_ENABLE_MODULES = YES; 290 | CLANG_ENABLE_OBJC_ARC = YES; 291 | CLANG_WARN_BOOL_CONVERSION = YES; 292 | CLANG_WARN_CONSTANT_CONVERSION = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_EMPTY_BODY = YES; 295 | CLANG_WARN_ENUM_CONVERSION = YES; 296 | CLANG_WARN_INT_CONVERSION = YES; 297 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 298 | CLANG_WARN_UNREACHABLE_CODE = YES; 299 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 300 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 301 | COPY_PHASE_STRIP = NO; 302 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 303 | ENABLE_NS_ASSERTIONS = NO; 304 | ENABLE_STRICT_OBJC_MSGSEND = YES; 305 | GCC_C_LANGUAGE_STANDARD = gnu99; 306 | GCC_NO_COMMON_BLOCKS = YES; 307 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 308 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 309 | GCC_WARN_UNDECLARED_SELECTOR = YES; 310 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 311 | GCC_WARN_UNUSED_FUNCTION = YES; 312 | GCC_WARN_UNUSED_VARIABLE = YES; 313 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 314 | MTL_ENABLE_DEBUG_INFO = NO; 315 | SDKROOT = iphoneos; 316 | VALIDATE_PRODUCT = YES; 317 | }; 318 | name = Release; 319 | }; 320 | 89B9FB4A1C7959F600E8AA51 /* Debug */ = { 321 | isa = XCBuildConfiguration; 322 | buildSettings = { 323 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 324 | INFOPLIST_FILE = UploadFileTest/Info.plist; 325 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 326 | PRODUCT_BUNDLE_IDENTIFIER = shiwei.UploadFileTest; 327 | PRODUCT_NAME = "$(TARGET_NAME)"; 328 | }; 329 | name = Debug; 330 | }; 331 | 89B9FB4B1C7959F600E8AA51 /* Release */ = { 332 | isa = XCBuildConfiguration; 333 | buildSettings = { 334 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 335 | INFOPLIST_FILE = UploadFileTest/Info.plist; 336 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 337 | PRODUCT_BUNDLE_IDENTIFIER = shiwei.UploadFileTest; 338 | PRODUCT_NAME = "$(TARGET_NAME)"; 339 | }; 340 | name = Release; 341 | }; 342 | /* End XCBuildConfiguration section */ 343 | 344 | /* Begin XCConfigurationList section */ 345 | 89B9FB2D1C7959F600E8AA51 /* Build configuration list for PBXProject "UploadFileTest" */ = { 346 | isa = XCConfigurationList; 347 | buildConfigurations = ( 348 | 89B9FB471C7959F600E8AA51 /* Debug */, 349 | 89B9FB481C7959F600E8AA51 /* Release */, 350 | ); 351 | defaultConfigurationIsVisible = 0; 352 | defaultConfigurationName = Release; 353 | }; 354 | 89B9FB491C7959F600E8AA51 /* Build configuration list for PBXNativeTarget "UploadFileTest" */ = { 355 | isa = XCConfigurationList; 356 | buildConfigurations = ( 357 | 89B9FB4A1C7959F600E8AA51 /* Debug */, 358 | 89B9FB4B1C7959F600E8AA51 /* Release */, 359 | ); 360 | defaultConfigurationIsVisible = 0; 361 | defaultConfigurationName = Release; 362 | }; 363 | /* End XCConfigurationList section */ 364 | }; 365 | rootObject = 89B9FB2A1C7959F600E8AA51 /* Project object */; 366 | } 367 | --------------------------------------------------------------------------------