Commit e61797b3 by zhangyunjie

添加七牛上传

parent d0c4407d
......@@ -147,6 +147,21 @@
<action selector="uploadFile:" destination="BYZ-38-t0r" eventType="touchUpInside" id="f1e-t6-rq0"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="bxC-wQ-owS">
<rect key="frame" x="15" y="480" width="62" height="30"/>
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<state key="normal" title="获取图片"/>
<connections>
<action selector="getImage:" destination="BYZ-38-t0r" eventType="touchUpInside" id="cbb-Dd-m3G"/>
</connections>
</button>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="01u-sn-4fM">
<rect key="frame" x="87" y="480" width="50" height="50"/>
<constraints>
<constraint firstAttribute="width" constant="50" id="ImC-C3-Oze"/>
<constraint firstAttribute="height" constant="50" id="h6U-AZ-Ejp"/>
</constraints>
</imageView>
</subviews>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
......@@ -158,9 +173,12 @@
<constraint firstItem="Cy1-S1-DPz" firstAttribute="height" secondItem="dRe-f0-gnl" secondAttribute="height" id="8qa-si-8ig"/>
<constraint firstItem="m3k-LM-GSV" firstAttribute="leading" secondItem="dRe-f0-gnl" secondAttribute="leading" id="97H-yt-Mwa"/>
<constraint firstItem="dRe-f0-gnl" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="15" id="A4C-6b-WCr"/>
<constraint firstItem="bxC-wQ-owS" firstAttribute="leading" secondItem="dRe-f0-gnl" secondAttribute="leading" id="ASK-51-Usk"/>
<constraint firstItem="so4-rI-aRi" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" id="Acv-YJ-6xY"/>
<constraint firstItem="dRe-f0-gnl" firstAttribute="top" secondItem="so4-rI-aRi" secondAttribute="bottom" constant="10" id="AvN-lQ-0c4"/>
<constraint firstItem="Cy1-S1-DPz" firstAttribute="top" secondItem="uRU-q5-QzB" secondAttribute="bottom" constant="5" id="CFi-VG-VAh"/>
<constraint firstItem="01u-sn-4fM" firstAttribute="top" secondItem="bxC-wQ-owS" secondAttribute="top" id="Evh-9r-mjB"/>
<constraint firstItem="bxC-wQ-owS" firstAttribute="top" secondItem="Cy1-S1-DPz" secondAttribute="bottom" constant="5" id="HV2-Wc-8Yi"/>
<constraint firstItem="F7y-mH-mpC" firstAttribute="height" secondItem="TnX-iH-azN" secondAttribute="height" id="HV9-jc-VLg"/>
<constraint firstItem="F7y-mH-mpC" firstAttribute="top" secondItem="9JE-Lz-Dma" secondAttribute="bottom" constant="5" id="HdJ-KZ-Mo0"/>
<constraint firstItem="so4-rI-aRi" firstAttribute="top" secondItem="HDM-va-7kG" secondAttribute="bottom" constant="5" id="JGR-v7-Dr6"/>
......@@ -169,6 +187,7 @@
<constraint firstItem="m3k-LM-GSV" firstAttribute="top" secondItem="7fD-Hf-Afy" secondAttribute="bottom" constant="5" id="Lxq-EJ-ByY"/>
<constraint firstItem="2eb-Vp-qLt" firstAttribute="height" secondItem="dRe-f0-gnl" secondAttribute="height" id="M7d-CM-zWv"/>
<constraint firstItem="2eb-Vp-qLt" firstAttribute="top" secondItem="dRe-f0-gnl" secondAttribute="bottom" constant="5" id="QLW-Tp-TY4"/>
<constraint firstItem="bxC-wQ-owS" firstAttribute="height" secondItem="dRe-f0-gnl" secondAttribute="height" id="ROb-ls-OKO"/>
<constraint firstItem="TnX-iH-azN" firstAttribute="leading" secondItem="8bC-Xf-vdC" secondAttribute="leading" constant="15" id="UOK-BA-rIV"/>
<constraint firstItem="Cy1-S1-DPz" firstAttribute="leading" secondItem="dRe-f0-gnl" secondAttribute="leading" id="Y9c-yU-8ZX"/>
<constraint firstAttribute="trailing" secondItem="HDM-va-7kG" secondAttribute="trailing" id="YX6-FQ-G4J"/>
......@@ -188,12 +207,14 @@
<constraint firstItem="Vmx-zP-DRW" firstAttribute="height" secondItem="dRe-f0-gnl" secondAttribute="height" id="uLF-IL-l61"/>
<constraint firstItem="Vmx-zP-DRW" firstAttribute="leading" secondItem="dRe-f0-gnl" secondAttribute="trailing" constant="10" id="vfp-Yh-YD6"/>
<constraint firstItem="9JE-Lz-Dma" firstAttribute="top" secondItem="1dp-RW-FhV" secondAttribute="bottom" constant="5" id="xMf-AL-l1H"/>
<constraint firstItem="01u-sn-4fM" firstAttribute="leading" secondItem="bxC-wQ-owS" secondAttribute="trailing" constant="10" id="xNi-Lk-dWo"/>
<constraint firstItem="FOH-XA-D8x" firstAttribute="height" secondItem="dRe-f0-gnl" secondAttribute="height" id="yrM-M1-11o"/>
<constraint firstItem="Vmx-zP-DRW" firstAttribute="top" secondItem="dRe-f0-gnl" secondAttribute="top" id="zxs-bV-awe"/>
</constraints>
</view>
<connections>
<outlet property="changeEnvironmentBtn" destination="so4-rI-aRi" id="ong-vG-zJ6"/>
<outlet property="showImage" destination="01u-sn-4fM" id="Tl0-7d-FXH"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="dkx-z0-nzr" sceneMemberID="firstResponder"/>
......
......@@ -2,8 +2,12 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>App需要您的同意,才能访问相册</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>NSCameraUsageDescription</key>
<string>App需要您的同意,才能访问相机</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
......
......@@ -11,7 +11,10 @@
#import "OffcnNetworkExecutor.h"
#import <oimcore/oimcoreAdapter.h>
@interface ViewController ()<OIMCoreDelegate>
#import <QiniuSDK.h>
#import "QNTransactionManager.h"
@interface ViewController ()<OIMCoreDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
@property (weak, nonatomic) IBOutlet UIButton *changeEnvironmentBtn;
......@@ -22,6 +25,10 @@
@property (strong, nonatomic) NSMutableDictionary *dataDic;
@property (strong, nonatomic) OIMCoreAdapter *adapter;
@property (nonatomic, strong) NSString *QNToken;
@property (nonatomic, strong) UIImage *pickImage;
@property (weak, nonatomic) IBOutlet UIImageView *showImage;
@end
@implementation ViewController
......@@ -108,14 +115,41 @@
}];
}
- (IBAction)getImage:(UIButton *)sender {
[self gotoImageLibrary];
}
- (IBAction)uploadFile:(UIButton *)sender {
__weak typeof(self) weakSelf = self;
[OffcnNetworkExecutor requestUploadTokenFinished:^(BOOL success, id response, BaseResponse *baseResponse) {
NSString *token = [NSString stringWithFormat:@"%@",response];
weakSelf.QNToken = token;
NSLog(@"七牛token---%@",token);
NSData *imageData = UIImageJPEGRepresentation(weakSelf.pickImage, 0.5);
[weakSelf uploadToQNWithQNToken:weakSelf.QNToken fileData:imageData];
}];
}
-(void)uploadToQNWithQNToken:(NSString *)QNToken fileData:(NSData *)fileData{
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 putData:fileData key:nil token:self.QNToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"key ===== %@", key);
NSLog(@"resp ===== %@", resp);
//发送消息
NSString *dataStr = [NSString stringWithFormat:@"http://test-offcncloud-im.eoffcn.com/%@",resp[@"key"]];
NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithObject:dataStr forKey:@"msg"];
[OffcnNetworkExecutor requestSendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:self.msg_type msg:dataDic Finished:^(BOOL success, id response, BaseResponse *baseResponse) {
}];
}option:uploadOption];
}
- (void)viewDidLoad {
[super viewDidLoad];
......@@ -142,6 +176,29 @@
docDir = [docDir stringByAppendingPathComponent:@"test"];
return docDir;
}
#pragma mark UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey, id> *)info {
self.pickImage = info[UIImagePickerControllerOriginalImage];
self.showImage.image = self.pickImage;
[picker dismissViewControllerAnimated:YES completion:^{
}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
- (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 {
//访问图片库错误
}
}
//可旋转屏幕
- (BOOL)shouldAutorotate {
return NO;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment