Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2015-present, Parse, LLC.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.

---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: true
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: false
AlwaysBreakBeforeMultilineStrings: false
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 0
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: true
ExperimentalAutoDetectBinPacking: true
IndentCaseLabels: true
IndentWrappedFunctionNames: true
IndentFunctionDeclarationAfterType: true
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 140
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 120
PointerAlignment: Right
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: Never
BreakBeforeBraces: Attach
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 4
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
...
2 changes: 0 additions & 2 deletions QiniuDemo/QiniuDemo/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@

@property (strong, nonatomic) UIWindow *window;


@end

1 change: 0 additions & 1 deletion QiniuDemo/QiniuDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ @interface AppDelegate ()

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
return YES;
Expand Down
9 changes: 4 additions & 5 deletions QiniuDemo/QiniuDemo/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@
// Copyright © 2016年 Aaron. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <QiniuSDK.h>
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@property (nonatomic, weak) IBOutlet UIButton * chooseBtn;
@property (nonatomic, weak) IBOutlet UIButton * uploadBtn;
@property (nonatomic, weak) IBOutlet UIImageView * preViewImage;
@property (nonatomic, weak) IBOutlet UIButton* chooseBtn;
@property (nonatomic, weak) IBOutlet UIButton* uploadBtn;
@property (nonatomic, weak) IBOutlet UIImageView* preViewImage;

@end

129 changes: 58 additions & 71 deletions QiniuDemo/QiniuDemo/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#import "AFNetworking.h"
#import "UIImageView+AFNetworking.h"

@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@interface ViewController () <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (nonatomic, strong) NSString * token;
@property (nonatomic, strong) NSString * domain;
@property (nonatomic, strong) UIImage * pickImage;
@property (nonatomic, strong) NSString *token;
@property (nonatomic, strong) NSString *domain;
@property (nonatomic, strong) UIImage *pickImage;

@end

Expand All @@ -26,128 +26,115 @@ - (void)viewDidLoad {
self.title = @"七牛云上传";
}

- (IBAction)chooseAction:(id)sender
{
- (IBAction)chooseAction:(id)sender {
[self gotoImageLibrary];
}

- (IBAction)uploadAction:(id)sender
{
- (IBAction)uploadAction:(id)sender {
if (self.pickImage == nil) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"还未选择图片"
message:@""
delegate:nil
cancelButtonTitle:@"OK!"
otherButtonTitles:nil];
initWithTitle:@"还未选择图片"
message:@""
delegate:nil
cancelButtonTitle:@"OK!"
otherButtonTitles:nil];
[alert show];
}else
{
[self getTokenFromQN];
} else {
[self getTokenFromQN];
}
}

- (void)getTokenFromQN
{
- (void)getTokenFromQN {
//1.管理器
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
// //2.设置登录参数
// NSDictionary *dict = @{ @"username":@"xn", @"password":@"123" };

// //2.设置登录参数
// NSDictionary *dict = @{ @"username":@"xn", @"password":@"123" };

//3.请求
[manager POST:@"http://115.231.183.102:9090/api/quick_start/simple_image_example_token.php" parameters:nil success: ^(AFHTTPRequestOperation *operation, id responseObject) {
[manager POST:@"http://115.231.183.102:9090/api/quick_start/simple_image_example_token.php" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
self.domain = responseObject[@"domain"];
self.token = responseObject[@"uptoken"];
[self uploadImageToQNFilePath:[self getImagePath:self.pickImage]];
} failure: ^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
}];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@", error);
}];
}

-(void)uploadImageToQNFilePath:(NSString *)filePath
{
- (void)uploadImageToQNFilePath:(NSString *)filePath {
QNUploadManager *upManager = [[QNUploadManager alloc] init];
QNUploadOption * uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
NSLog(@"percent == %.2f",percent);
} params:nil checkCrc:NO cancellationSignal:nil];
[upManager putFile:filePath key: nil token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
NSLog(@"percent == %.2f", percent);
}
params:nil
checkCrc:NO
cancellationSignal:nil];
[upManager putFile:filePath key:nil token:self.token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"resp ===== %@", resp);
NSLog(@"%@/%@",self.domain,resp[@"key"]);
[self.preViewImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",self.domain,resp[@"key"]]] placeholderImage:[UIImage imageNamed:@"placeholder.jpg"]];

} option:uploadOption];

}
NSLog(@"%@/%@", self.domain, resp[@"key"]);
[self.preViewImage setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.domain, resp[@"key"]]] placeholderImage:[UIImage imageNamed:@"placeholder.jpg"]];

}
option:uploadOption];
}

- (void)gotoImageLibrary
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
- (void)gotoImageLibrary {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}else {
} else {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"访问图片库错误"
message:@""
delegate:nil
cancelButtonTitle:@"OK!"
otherButtonTitles:nil];
initWithTitle:@"访问图片库错误"
message:@""
delegate:nil
cancelButtonTitle:@"OK!"
otherButtonTitles:nil];
[alert show];
}
}



//再调用以下委托:
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
didFinishPickingImage:(UIImage *)image
editingInfo:(NSDictionary *)editingInfo {
self.pickImage = image; //imageView为自己定义的UIImageView
[picker dismissViewControllerAnimated:YES completion:^{
}];


}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];

}

//照片获取本地路径转换
-(NSString *)getImagePath:(UIImage *)Image
{
NSString * filePath = nil;
NSData * data = nil;
if (UIImagePNGRepresentation(Image) == nil)
{
- (NSString *)getImagePath:(UIImage *)Image {
NSString *filePath = nil;
NSData *data = nil;
if (UIImagePNGRepresentation(Image) == nil) {
data = UIImageJPEGRepresentation(Image, 1.0);
}
else
{
} else {
data = UIImagePNGRepresentation(Image);
}

//图片保存的路径
//这里将图片放在沙盒的documents文件夹中
NSString * DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString *DocumentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

//文件管理器
NSFileManager *fileManager = [NSFileManager defaultManager];

//把刚刚图片转换的data对象拷贝至沙盒中
[fileManager createDirectoryAtPath:DocumentsPath withIntermediateDirectories:YES attributes:nil error:nil];
NSString * ImagePath = [[NSString alloc]initWithFormat:@"/theFirstImage.png"];
NSString *ImagePath = [[NSString alloc] initWithFormat:@"/theFirstImage.png"];
[fileManager createFileAtPath:[DocumentsPath stringByAppendingString:ImagePath] contents:data attributes:nil];

//得到选择后沙盒中图片的完整路径
filePath = [[NSString alloc]initWithFormat:@"%@%@",DocumentsPath,ImagePath];
filePath = [[NSString alloc] initWithFormat:@"%@%@", DocumentsPath, ImagePath];
return filePath;
}

Expand Down
4 changes: 2 additions & 2 deletions QiniuDemo/QiniuDemo/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
// Copyright © 2016年 Aaron. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "AppDelegate.h"
#import <UIKit/UIKit.h>

int main(int argc, char * argv[]) {
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
Expand Down
6 changes: 3 additions & 3 deletions QiniuDemo/QiniuDemoUITests/QiniuDemoUITests.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ @implementation QiniuDemoUITests

- (void)setUp {
[super setUp];

// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
self.continueAfterFailure = NO;
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
[[[XCUIApplication alloc] init] launch];

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

Expand Down
Loading