| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -588,6 +588,7 @@ | |||
| 588 | 588 | 8EF83F8A19E92AA500E86DE7 /* SettingTagsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF83F8919E92AA500E86DE7 /* SettingTagsViewController.m */; }; | |
| 589 | 589 | 8EF83F8C19E931D200E86DE7 /* me_info_arrow_left@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 8EF83F8B19E931D200E86DE7 /* me_info_arrow_left@2x.png */; }; | |
| 590 | 590 | 8EF83F9419EB78CC00E86DE7 /* SettingTextViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8EF83F9319EB78CC00E86DE7 /* SettingTextViewController.m */; }; | |
| 591 | + B93D904B1ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.m in Sources */ = {isa = PBXBuildFile; fileRef = B93D904A1ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.m */; }; | ||
| 591 | 592 | B94C1B691AC945D30000C271 /* NewProjectViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B94C1B681AC945D30000C271 /* NewProjectViewController.m */; }; | |
| 592 | 593 | B94C1B6B1AC945FB0000C271 /* NewProject.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B94C1B6A1AC945FB0000C271 /* NewProject.storyboard */; }; | |
| 593 | 594 | B94C1B6E1AC98CCE0000C271 /* NewProjectTypeViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B94C1B6D1AC98CCE0000C271 /* NewProjectTypeViewController.m */; }; | |
@@ -1497,6 +1498,8 @@ | |||
| 1497 | 1498 | 8EF83F8B19E931D200E86DE7 /* me_info_arrow_left@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "me_info_arrow_left@2x.png"; sourceTree = "<group>"; }; | |
| 1498 | 1499 | 8EF83F9219EB78CC00E86DE7 /* SettingTextViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingTextViewController.h; sourceTree = "<group>"; }; | |
| 1499 | 1500 | 8EF83F9319EB78CC00E86DE7 /* SettingTextViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingTextViewController.m; sourceTree = "<group>"; }; | |
| 1501 | + B93D90491ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProjectDeleteAlertControllerVisualStyle.h; sourceTree = "<group>"; }; | ||
| 1502 | + B93D904A1ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProjectDeleteAlertControllerVisualStyle.m; sourceTree = "<group>"; }; | ||
| 1500 | 1503 | B94C1B671AC945D30000C271 /* NewProjectViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NewProjectViewController.h; sourceTree = "<group>"; }; | |
| 1501 | 1504 | B94C1B681AC945D30000C271 /* NewProjectViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NewProjectViewController.m; sourceTree = "<group>"; }; | |
| 1502 | 1505 | B94C1B6A1AC945FB0000C271 /* NewProject.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = NewProject.storyboard; sourceTree = "<group>"; }; | |
@@ -3058,6 +3061,8 @@ | |||
| 3058 | 3061 | B9A00D811ACA3A17008BA008 /* ProjectSettingViewController.m */, | |
| 3059 | 3062 | B9A00D831ACA3A55008BA008 /* ProjectAdvancedSettingViewController.h */, | |
| 3060 | 3063 | B9A00D841ACA3A55008BA008 /* ProjectAdvancedSettingViewController.m */, | |
| 3064 | + B93D90491ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.h */, | ||
| 3065 | + B93D904A1ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.m */, | ||
| 3061 | 3066 | ); | |
| 3062 | 3067 | path = ProjectSetting; | |
| 3063 | 3068 | sourceTree = "<group>"; | |
@@ -3094,7 +3099,6 @@ | |||
| 3094 | 3099 | ORGANIZATIONNAME = Coding; | |
| 3095 | 3100 | TargetAttributes = { | |
| 3096 | 3101 | 8E47700F198770E700997D05 = { | |
| 3097 | - DevelopmentTeam = QN5Z87S3LH; | ||
| 3098 | 3102 | SystemCapabilities = { | |
| 3099 | 3103 | com.apple.BackgroundModes = { | |
| 3100 | 3104 | enabled = 0; | |
@@ -3640,6 +3644,7 @@ | |||
| 3640 | 3644 | 4EA7F15A1A6D192B00A046BD /* SDImageCache.m in Sources */, | |
| 3641 | 3645 | 4EBB624C1A6F526C0045DAEF /* NJKWebViewProgress.m in Sources */, | |
| 3642 | 3646 | 8EA6D13C19E240C40076D59C /* Tweet_RootViewController.m in Sources */, | |
| 3647 | + B93D904B1ACBA3110057A6EE /* ProjectDeleteAlertControllerVisualStyle.m in Sources */, | ||
| 3643 | 3648 | 4E1A22851AB172C400CFC14F /* ProjectItemsCell.m in Sources */, | |
| 3644 | 3649 | 4ECE8B051A3946C10021E29C /* WebContentManager.m in Sources */, | |
| 3645 | 3650 | 8EA6D1F819E240C40076D59C /* MJPhotoBrowser.m in Sources */, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -134,6 +134,7 @@ -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cel | |||
| 134 | 134 | } | |
| 135 | 135 | ||
| 136 | 136 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
| 137 | + [tableView deselectRowAtIndexPath:indexPath animated:YES]; | ||
| 137 | 138 | ||
| 138 | 139 | // Checkmark | |
| 139 | 140 | if (self.checkedIndexPath){ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,6 +14,7 @@ @interface NewProjectViewController ()<NewProjectTypeDelegate,UITextFieldDelegat | |||
| 14 | 14 | ||
| 15 | 15 | @property (nonatomic, assign) NewProjectType projectType; | |
| 16 | 16 | @property (nonatomic, strong) UIBarButtonItem *submitButtonItem; | |
| 17 | + @property (nonatomic, strong) UIImage *projectIconImage; | ||
| 17 | 18 | ||
| 18 | 19 | @end | |
| 19 | 20 | ||
@@ -62,15 +63,17 @@ -(void)selectProjectImage{ | |||
| 62 | 63 | }else{ | |
| 63 | 64 | avatarPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | |
| 64 | 65 | } | |
| 66 | + avatarPicker.allowsEditing = YES; | ||
| 65 | 67 | [self presentViewController:avatarPicker animated:YES completion:nil]; | |
| 66 | 68 | }] showInView:self.view]; | |
| 67 | 69 | } | |
| 68 | 70 | ||
| 69 | 71 | -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ | |
| 70 | - UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; | ||
| 72 | + UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage]; | ||
| 71 | 73 | ||
| 72 | 74 | if (image) { | |
| 73 | 75 | self.projectImageView.image = image; | |
| 76 | + self.projectIconImage = image; | ||
| 74 | 77 | } | |
| 75 | 78 | ||
| 76 | 79 | [picker dismissViewControllerAnimated:YES completion:nil]; | |
@@ -100,9 +103,14 @@ -(void)submit{ | |||
| 100 | 103 | project.is_public = @NO; | |
| 101 | 104 | } | |
| 102 | 105 | ||
| 106 | + self.submitButtonItem.enabled = NO; | ||
| 107 | + | ||
| 103 | 108 | // 效验完成,开始发送请求创建项目 | |
| 104 | - [[Coding_NetAPIManager sharedManager] request_NewProject_WithObj:project andBlock:^(Project *data, NSError *error) { | ||
| 105 | - [self.navigationController popToRootViewControllerAnimated:YES]; | ||
| 109 | + [[Coding_NetAPIManager sharedManager] request_NewProject_WithObj:project image:self.projectIconImage andBlock:^(Project *data, NSError *error) { | ||
| 110 | + if (!error) { | ||
| 111 | + [self.navigationController popToRootViewControllerAnimated:YES]; | ||
| 112 | + } | ||
| 113 | + self.submitButtonItem.enabled = YES; | ||
| 106 | 114 | }]; | |
| 107 | 115 | }else{ | |
| 108 | 116 | [[[UIAlertView alloc] initWithTitle:@"提示" message:@"项目名只允许字母、数字或者下划线(_)、中划线(-),必须以字母或者数字开头,且不能以.git结尾" delegate:nil cancelButtonTitle:@"取消" otherButtonTitles: nil] show]; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,10 @@ | |||
| 9 | 9 | #import "ProjectAdvancedSettingViewController.h" | |
| 10 | 10 | #import "Coding_NetAPIManager.h" | |
| 11 | 11 | ||
| 12 | - @interface ProjectAdvancedSettingViewController ()<UIAlertViewDelegate> | ||
| 12 | + #import <SDCAlertController.h> | ||
| 13 | + #import "ProjectDeleteAlertControllerVisualStyle.h" | ||
| 14 | + | ||
| 15 | + @interface ProjectAdvancedSettingViewController () | ||
| 13 | 16 | ||
| 14 | 17 | @end | |
| 15 | 18 | ||
@@ -52,15 +55,27 @@ -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cel | |||
| 52 | 55 | -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ | |
| 53 | 56 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; | |
| 54 | 57 | ||
| 55 | - UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"需要验证密码" message:@"这是一个危险的操作,请提供登录密码确认!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; | ||
| 56 | - alert.alertViewStyle = UIAlertViewStyleSecureTextInput; | ||
| 57 | - [alert show]; | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ | ||
| 61 | - if (buttonIndex == 1) { | ||
| 62 | - // 确定 | ||
| 63 | - NSString *password = [[alertView textFieldAtIndex:0].text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
| 58 | + static NSString *title = @"需要验证密码"; | ||
| 59 | + static NSString *message = @"这是一个危险的操作,请提供登录密码确认!"; | ||
| 60 | + | ||
| 61 | + SDCAlertController *alert = [SDCAlertController alertControllerWithTitle:title message:message preferredStyle:SDCAlertControllerStyleAlert]; | ||
| 62 | + | ||
| 63 | + // Style | ||
| 64 | + alert.visualStyle = [ProjectDeleteAlertControllerVisualStyle new]; | ||
| 65 | + | ||
| 66 | + // 添加密码框 | ||
| 67 | + [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { | ||
| 68 | + textField.secureTextEntry = YES; | ||
| 69 | + }]; | ||
| 70 | + | ||
| 71 | + // 添加按钮 | ||
| 72 | + alert.actionLayout = SDCAlertControllerActionLayoutHorizontal; | ||
| 73 | + [alert addAction:[SDCAlertAction actionWithTitle:@"取消" style:SDCAlertActionStyleCancel handler:^(SDCAlertAction *action) { | ||
| 74 | + [alert dismissWithCompletion:nil]; | ||
| 75 | + }]]; | ||
| 76 | + [alert addAction:[SDCAlertAction actionWithTitle:@"确定" style:SDCAlertActionStyleDefault handler:^(SDCAlertAction *action) { | ||
| 77 | + UITextField *passwordTextField = [[alert textFields] firstObject]; | ||
| 78 | + NSString *password = [passwordTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; | ||
| 64 | 79 | ||
| 65 | 80 | if (password > 0) { | |
| 66 | 81 | // 删除项目 | |
@@ -71,7 +86,9 @@ -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)button | |||
| 71 | 86 | ||
| 72 | 87 | }]; | |
| 73 | 88 | } | |
| 74 | - } | ||
| 89 | + }]]; | ||
| 90 | + | ||
| 91 | + [alert presentWithCompletion:nil]; | ||
| 75 | 92 | } | |
| 76 | 93 | ||
| 77 | 94 | @end | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,13 @@ | |||
| 1 | + // | ||
| 2 | + // ProjectDeleteAlertControllerVisualStyle.h | ||
| 3 | + // Coding_iOS | ||
| 4 | + // | ||
| 5 | + // Created by isaced on 15/4/1. | ||
| 6 | + // Copyright (c) 2015年 Coding. All rights reserved. | ||
| 7 | + // | ||
| 8 | + | ||
| 9 | + #import "SDCAlertControllerDefaultVisualStyle.h" | ||
| 10 | + | ||
| 11 | + @interface ProjectDeleteAlertControllerVisualStyle : SDCAlertControllerDefaultVisualStyle | ||
| 12 | + | ||
| 13 | + @end | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,29 @@ | |||
| 1 | + // | ||
| 2 | + // ProjectDeleteAlertControllerVisualStyle.m | ||
| 3 | + // Coding_iOS | ||
| 4 | + // | ||
| 5 | + // Created by isaced on 15/4/1. | ||
| 6 | + // Copyright (c) 2015年 Coding. All rights reserved. | ||
| 7 | + // | ||
| 8 | + | ||
| 9 | + #import "ProjectDeleteAlertControllerVisualStyle.h" | ||
| 10 | + | ||
| 11 | + @implementation ProjectDeleteAlertControllerVisualStyle | ||
| 12 | + | ||
| 13 | + -(UIColor *)titleLabelColor{ | ||
| 14 | + return [UIColor colorWithRGBHex:0x222222]; | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + -(UIColor *)messageLabelColor{ | ||
| 18 | + return [UIColor colorWithRGBHex:0xf34a4a]; | ||
| 19 | + } | ||
| 20 | + | ||
| 21 | + - (CGFloat)labelSpacing { | ||
| 22 | + return 30; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + - (CGFloat)messageLabelBottomSpacing { | ||
| 26 | + return 20; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + @end | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,9 +11,10 @@ | |||
| 11 | 11 | #import "UIImageView+WebCache.h" | |
| 12 | 12 | #import "Coding_NetAPIManager.h" | |
| 13 | 13 | ||
| 14 | - @interface ProjectSettingViewController ()<UITextViewDelegate> | ||
| 14 | + @interface ProjectSettingViewController ()<UITextViewDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> | ||
| 15 | 15 | ||
| 16 | 16 | @property (nonatomic, strong) UIBarButtonItem *submitButtonItem; | |
| 17 | + @property (nonatomic, strong) UIImage *projectIconImage; | ||
| 17 | 18 | ||
| 18 | 19 | @end | |
| 19 | 20 | ||
@@ -34,6 +35,8 @@ - (void)viewDidLoad { | |||
| 34 | 35 | // | |
| 35 | 36 | self.projectImageView.layer.cornerRadius = 5; | |
| 36 | 37 | [self.projectImageView sd_setImageWithURL:[self.project.icon urlImageWithCodePathResizeToView:self.projectImageView]]; | |
| 38 | + UITapGestureRecognizer *tapProjectImageViewGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectProjectImage)]; | ||
| 39 | + [self.projectImageView addGestureRecognizer:tapProjectImageViewGR]; | ||
| 37 | 40 | ||
| 38 | 41 | // 添加 “完成” 按钮 | |
| 39 | 42 | self.submitButtonItem = [UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(submit)]; | |
@@ -45,13 +48,52 @@ - (void)viewDidLoad { | |||
| 45 | 48 | -(void)submit{ | |
| 46 | 49 | self.project.description_mine = [self.descTextView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; | |
| 47 | 50 | ||
| 51 | + self.submitButtonItem.enabled = NO; | ||
| 52 | + | ||
| 48 | 53 | // 更新项目 | |
| 49 | - [[Coding_NetAPIManager sharedManager] request_UpdateProject_WithObj:self.project andBlock:^(Project *data, NSError *error) { | ||
| 50 | - [self.navigationController popToRootViewControllerAnimated:YES]; | ||
| 54 | + [[Coding_NetAPIManager sharedManager] request_UpdateProject_WithObj:self.project image:self.projectIconImage andBlock:^(Project *data, NSError *error) { | ||
| 55 | + if (!error) { | ||
| 56 | + [self.navigationController popToRootViewControllerAnimated:YES]; | ||
| 57 | + } | ||
| 58 | + self.submitButtonItem.enabled = YES; | ||
| 51 | 59 | }]; | |
| 52 | 60 | ||
| 53 | 61 | } | |
| 54 | 62 | ||
| 63 | + -(void)selectProjectImage{ | ||
| 64 | + [[UIActionSheet bk_actionSheetCustomWithTitle:@"选择照片" buttonTitles:@[@"拍照",@"从相册选择"] destructiveTitle:nil cancelTitle:@"取消" andDidDismissBlock:^(UIActionSheet *sheet, NSInteger index) { | ||
| 65 | + | ||
| 66 | + if (index > 1) { | ||
| 67 | + return ; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + UIImagePickerController *avatarPicker = [[UIImagePickerController alloc] init]; | ||
| 71 | + avatarPicker.delegate = self; | ||
| 72 | + if (index == 0) { | ||
| 73 | + avatarPicker.sourceType = UIImagePickerControllerSourceTypeCamera; | ||
| 74 | + }else{ | ||
| 75 | + avatarPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; | ||
| 76 | + } | ||
| 77 | + [self presentViewController:avatarPicker animated:YES completion:nil]; | ||
| 78 | + }] showInView:self.view]; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ | ||
| 82 | + UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; | ||
| 83 | + | ||
| 84 | + if (image) { | ||
| 85 | + self.projectImageView.image = image; | ||
| 86 | + self.projectIconImage = image; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + [picker dismissViewControllerAnimated:YES completion:nil]; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ | ||
| 93 | + [picker dismissViewControllerAnimated:YES completion:nil]; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + | ||
| 55 | 97 | -(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{ | |
| 56 | 98 | NSString *string = [textView.text stringByReplacingCharactersInRange:range withString:text]; | |
| 57 | 99 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,11 +137,11 @@ -(NSDictionary *)toCreateParams{ | |||
| 137 | 137 | return @{@"name":self.name, | |
| 138 | 138 | @"description":self.description_mine, | |
| 139 | 139 | @"type":type, | |
| 140 | - @"gitEnable":@"false", | ||
| 140 | + @"gitEnabled":@"false", | ||
| 141 | 141 | @"gitReadmeEnabled":@"false", | |
| 142 | 142 | @"gitIgnore":@"no", | |
| 143 | 143 | @"gitLicense":@"no", | |
| 144 | - @"importFrom":@"no", | ||
| 144 | + // @"importFrom":@"no", | ||
| 145 | 145 | @"vcsType":@"git"}; | |
| 146 | 146 | } | |
| 147 | 147 | ||
@@ -162,8 +162,8 @@ -(NSString *)toDeletePath{ | |||
| 162 | 162 | } | |
| 163 | 163 | ||
| 164 | 164 | -(NSDictionary *)toDeleteParamsWithPassword:(NSString *)password{ | |
| 165 | - return @{@"user_name":[Login curLoginUser].email, | ||
| 166 | - @"project_name":self.name, | ||
| 165 | + return @{@"user_name":[Login curLoginUser].name, | ||
| 166 | + @"name":self.name, | ||
| 167 | 167 | @"porject_id":[self.id stringValue], | |
| 168 | 168 | @"password":[password sha1Str]}; | |
| 169 | 169 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -35,6 +35,13 @@ typedef NS_ENUM(NSInteger, IllegalContentType) { | |||
| 35 | 35 | withMethodType:(int)NetworkMethod | |
| 36 | 36 | andBlock:(void (^)(id data, NSError *error))block; | |
| 37 | 37 | ||
| 38 | + - (void)requestJsonDataWithPath:(NSString *)aPath | ||
| 39 | + file:(NSDictionary *)file | ||
| 40 | + withParams:(NSDictionary*)params | ||
| 41 | + withMethodType:(int)NetworkMethod | ||
| 42 | + andBlock:(void (^)(id data, NSError *error))block; | ||
| 43 | + | ||
| 44 | + | ||
| 38 | 45 | - (void)reportIllegalContentWithType:(IllegalContentType)type | |
| 39 | 46 | withParams:(NSDictionary*)params; | |
| 40 | 47 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -116,6 +116,61 @@ - (void)requestJsonDataWithPath:(NSString *)aPath | |||
| 116 | 116 | } | |
| 117 | 117 | } | |
| 118 | 118 | ||
| 119 | + -(void)requestJsonDataWithPath:(NSString *)aPath file:(NSDictionary *)file withParams:(NSDictionary *)params withMethodType:(int)NetworkMethod andBlock:(void (^)(id, NSError *))block{ | ||
| 120 | + //log请求数据 | ||
| 121 | + DebugLog(@"\n===========request===========\n%@:\n%@", aPath, params); | ||
| 122 | + aPath = [aPath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; | ||
| 123 | + | ||
| 124 | + // Data | ||
| 125 | + NSData *data; | ||
| 126 | + NSString *name, *fileName; | ||
| 127 | + | ||
| 128 | + if (file) { | ||
| 129 | + UIImage *image = file[@"image"]; | ||
| 130 | + | ||
| 131 | + // 缩小到最大 800x800 | ||
| 132 | + image = [image scaledToMaxSize:CGSizeMake(799, 799)]; | ||
| 133 | + | ||
| 134 | + // 压缩 | ||
| 135 | + data = UIImageJPEGRepresentation(image, 1.0); | ||
| 136 | + if ((float)data.length/1024 > 1000) { | ||
| 137 | + data = UIImageJPEGRepresentation(image, 1024*1000.0/(float)data.length); | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + name = file[@"name"]; | ||
| 141 | + fileName = file[@"fileName"]; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + switch (NetworkMethod) { | ||
| 145 | + case Post:{ | ||
| 146 | + | ||
| 147 | + AFHTTPRequestOperation *operation = [self POST:aPath parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { | ||
| 148 | + if (file) { | ||
| 149 | + [formData appendPartWithFileData:data name:name fileName:fileName mimeType:@"image/jpeg"]; | ||
| 150 | + } | ||
| 151 | + } success:^(AFHTTPRequestOperation *operation, id responseObject) { | ||
| 152 | + DebugLog(@"\n===========response===========\n%@:\n%@", aPath, responseObject); | ||
| 153 | + id error = [self handleResponse:responseObject]; | ||
| 154 | + if (error) { | ||
| 155 | + block(nil, error); | ||
| 156 | + }else{ | ||
| 157 | + block(responseObject, nil); | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { | ||
| 161 | + DebugLog(@"\n===========response===========\n%@:\n%@", aPath, error); | ||
| 162 | + [self showError:error]; | ||
| 163 | + block(nil, error); | ||
| 164 | + }]; | ||
| 165 | + [operation start]; | ||
| 166 | + | ||
| 167 | + break; | ||
| 168 | + } | ||
| 169 | + default: | ||
| 170 | + break; | ||
| 171 | + } | ||
| 172 | + } | ||
| 173 | + | ||
| 119 | 174 | - (void)reportIllegalContentWithType:(IllegalContentType)type | |
| 120 | 175 | withParams:(NSDictionary*)params{ | |
| 121 | 176 | NSString *aPath; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments