Commit 49a8dc5c by zhangyunjie

OffcnUploadManager封装

parent e197908f
...@@ -205,6 +205,7 @@ ...@@ -205,6 +205,7 @@
A966274D24EBA56C0024EB54 /* OffcnIMSDKiOS.m in Sources */ = {isa = PBXBuildFile; fileRef = A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */; }; A966274D24EBA56C0024EB54 /* OffcnIMSDKiOS.m in Sources */ = {isa = PBXBuildFile; fileRef = A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */; };
A9D1B31424EE0772000F4662 /* oimcore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9D1B31224EE076B000F4662 /* oimcore.framework */; }; A9D1B31424EE0772000F4662 /* oimcore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9D1B31224EE076B000F4662 /* oimcore.framework */; };
A9D1B31524EE0772000F4662 /* oimcore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A9D1B31224EE076B000F4662 /* oimcore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; A9D1B31524EE0772000F4662 /* oimcore.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = A9D1B31224EE076B000F4662 /* oimcore.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
A9D1B31824EFAD8C000F4662 /* OffcnUploadManager.m in Sources */ = {isa = PBXBuildFile; fileRef = A9D1B31724EFAD8C000F4662 /* OffcnUploadManager.m */; };
B94FCB1053F8932068A11CC9 /* libPods-OffcnIMSDKiOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 49CE5E230A14D9B821170F61 /* libPods-OffcnIMSDKiOS.a */; }; B94FCB1053F8932068A11CC9 /* libPods-OffcnIMSDKiOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 49CE5E230A14D9B821170F61 /* libPods-OffcnIMSDKiOS.a */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
...@@ -635,6 +636,8 @@ ...@@ -635,6 +636,8 @@
A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OffcnIMSDKiOS.m; sourceTree = "<group>"; }; A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OffcnIMSDKiOS.m; sourceTree = "<group>"; };
A9662CBF24ECD98B0024EB54 /* OffcnIMSDKiOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OffcnIMSDKiOS.entitlements; sourceTree = "<group>"; }; A9662CBF24ECD98B0024EB54 /* OffcnIMSDKiOS.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = OffcnIMSDKiOS.entitlements; sourceTree = "<group>"; };
A9D1B31224EE076B000F4662 /* oimcore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = oimcore.framework; sourceTree = "<group>"; }; A9D1B31224EE076B000F4662 /* oimcore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = oimcore.framework; sourceTree = "<group>"; };
A9D1B31624EFAD8C000F4662 /* OffcnUploadManager.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OffcnUploadManager.h; sourceTree = "<group>"; };
A9D1B31724EFAD8C000F4662 /* OffcnUploadManager.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = OffcnUploadManager.m; sourceTree = "<group>"; };
D7DCDED1DEE7F99F223D5C73 /* Pods-OffcnIMSDKiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OffcnIMSDKiOS.release.xcconfig"; path = "Target Support Files/Pods-OffcnIMSDKiOS/Pods-OffcnIMSDKiOS.release.xcconfig"; sourceTree = "<group>"; }; D7DCDED1DEE7F99F223D5C73 /* Pods-OffcnIMSDKiOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OffcnIMSDKiOS.release.xcconfig"; path = "Target Support Files/Pods-OffcnIMSDKiOS/Pods-OffcnIMSDKiOS.release.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
...@@ -1434,6 +1437,8 @@ ...@@ -1434,6 +1437,8 @@
children = ( children = (
A966274B24EBA56C0024EB54 /* OffcnIMSDKiOS.h */, A966274B24EBA56C0024EB54 /* OffcnIMSDKiOS.h */,
A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */, A966274C24EBA56C0024EB54 /* OffcnIMSDKiOS.m */,
A9D1B31624EFAD8C000F4662 /* OffcnUploadManager.h */,
A9D1B31724EFAD8C000F4662 /* OffcnUploadManager.m */,
); );
path = "ExposedInterface-(外放接口)"; path = "ExposedInterface-(外放接口)";
sourceTree = "<group>"; sourceTree = "<group>";
...@@ -1600,6 +1605,7 @@ ...@@ -1600,6 +1605,7 @@
A96621BE24EA80A60024EB54 /* ZYJOSSGetBucketInfoResult.m in Sources */, A96621BE24EA80A60024EB54 /* ZYJOSSGetBucketInfoResult.m in Sources */,
A9661FD724EA7AD10024EB54 /* UIBarButtonItem+WNXBarButtonItem.m in Sources */, A9661FD724EA7AD10024EB54 /* UIBarButtonItem+WNXBarButtonItem.m in Sources */,
A966216A24EA80A60024EB54 /* ZYJPingFoundation.m in Sources */, A966216A24EA80A60024EB54 /* ZYJPingFoundation.m in Sources */,
A9D1B31824EFAD8C000F4662 /* OffcnUploadManager.m in Sources */,
A96621D424EA80A60024EB54 /* ZYJForegroundReconnection.m in Sources */, A96621D424EA80A60024EB54 /* ZYJForegroundReconnection.m in Sources */,
A966218924EA80A60024EB54 /* UIScrollView+ZYJMJExtension.m in Sources */, A966218924EA80A60024EB54 /* UIScrollView+ZYJMJExtension.m in Sources */,
A966218D24EA80A60024EB54 /* ZYJMJRefreshBackStateFooter.m in Sources */, A966218D24EA80A60024EB54 /* ZYJMJRefreshBackStateFooter.m in Sources */,
......
// //
...@@ -54,4 +54,14 @@ typedef void(^OffcnSDKReachabilityStatusCallBack)(OffcnSDKReachabilityStatus sta ...@@ -54,4 +54,14 @@ typedef void(^OffcnSDKReachabilityStatusCallBack)(OffcnSDKReachabilityStatus sta
//监听网络状态 //监听网络状态
-(void)startNotifierUseRealReachability; -(void)startNotifierUseRealReachability;
/// 发送消息
/// @param msg_fromID 发送人ID
/// @param msg_toID 接收人ID
/// @param msg_type 发送消息类型
/// @param text 文本
/// @param fileData 图片/音频/视频/文件
/// @param finished 结果回调
-(void)sendMsgWithMsg_fromID:(NSString *)msg_fromID msg_toID:(NSString *)msg_toID msg_type:(OffcnSDKMsgType)msg_type text:(NSString *)text fileData:(NSData *)fileData Finished:(void(^)(BOOL success,id response,NSString *errorMessage))finished;
@end @end
// //
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ZYJRealReachability.h" #import "ZYJRealReachability.h"
#import "SDGeneralDefine.h" #import "SDGeneralDefine.h"
#import "OffcnNetworkExecutor.h" #import "OffcnNetworkExecutor.h"
#import "OffcnUploadManager.h"
@interface OffcnIMSDKiOS () @interface OffcnIMSDKiOS ()
...@@ -27,6 +28,13 @@ static OffcnIMSDKiOS *liveTelecastSDK; ...@@ -27,6 +28,13 @@ static OffcnIMSDKiOS *liveTelecastSDK;
}); });
return liveTelecastSDK; return liveTelecastSDK;
} }
-(instancetype)init{
self = [super init];
if (self) {
}
return self;
}
-(void)setIsTest:(BOOL)isTest{ -(void)setIsTest:(BOOL)isTest{
if (isTest) { if (isTest) {
[[OffcnBaseNetworking sharedInstance] setServiceType:2]; [[OffcnBaseNetworking sharedInstance] setServiceType:2];
...@@ -35,6 +43,7 @@ static OffcnIMSDKiOS *liveTelecastSDK; ...@@ -35,6 +43,7 @@ static OffcnIMSDKiOS *liveTelecastSDK;
} }
_isTest = isTest; _isTest = isTest;
} }
#pragma mark - 使用RealReachability监听网络状态 #pragma mark - 使用RealReachability监听网络状态
-(void)startNotifierUseRealReachability{ -(void)startNotifierUseRealReachability{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:ZYJkRealReachabilityChangedNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(networkChanged:) name:ZYJkRealReachabilityChangedNotification object:nil];
...@@ -94,6 +103,42 @@ static OffcnIMSDKiOS *liveTelecastSDK; ...@@ -94,6 +103,42 @@ static OffcnIMSDKiOS *liveTelecastSDK;
} }
} }
#pragma mark - 操作事件
-(void)sendMsgWithMsg_fromID:(NSString *)msg_fromID msg_toID:(NSString *)msg_toID msg_type:(OffcnSDKMsgType)msg_type text:(NSString *)text fileData:(NSData *)fileData Finished:(void(^)(BOOL success,id response,NSString *errorMessage))finished{
//发送消息
if (msg_type == OffcnSDKMsgTypeText) {
if (!text || !text.length) {
text = @"";
}
NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithObject:text forKey:@"msg"];
[OffcnNetworkExecutor requestSendMsgWithMsg_fromID:msg_fromID msg_toID:msg_toID msg_type:msg_type msg:dataDic Finished:^(BOOL success, id response, BaseResponse *baseResponse) {
// {
// "msg_id" = "6a4b71b9-e372-11ea-88a4-4a5555fb6ab4";
// }
finished(success,nil,baseResponse.errorMessage);
}];
}else{
[[OffcnUploadManager defaultService] uploadToQNFileData:fileData Finished:^(BOOL success, id _Nonnull response, NSString * _Nonnull errorMessage) {
if (success) {
NSString *responseStr = @"";
if (response) {
responseStr = [NSString stringWithFormat:@"%@",response];
}
NSMutableDictionary *dataDic = [NSMutableDictionary dictionaryWithObject:responseStr forKey:@"url"];
[OffcnNetworkExecutor requestSendMsgWithMsg_fromID:msg_fromID msg_toID:msg_toID msg_type:msg_type msg:dataDic Finished:^(BOOL success, id response, BaseResponse *baseResponse) {
finished(success,nil,baseResponse.errorMessage);
}];
}else{
finished(success,nil,errorMessage);
}
}];
}
}
-(void)dealloc{ -(void)dealloc{
} }
......
//
//
// OffcnUploadManager.h
// OffcnIMSDKiOS
//
// Created by vockey on 2020/8/21.
// Copyright © 2020 offcn. All rights reserved.
//
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
@interface OffcnUploadManager : NSObject
+(OffcnUploadManager *)defaultService;
-(void)uploadToQNFileData:(NSData *)fileData Finished:(void(^)(BOOL success,id response,NSString *errorMessage))finished;
@end
NS_ASSUME_NONNULL_END
//
//
// OffcnUploadManager.m
// OffcnIMSDKiOS
//
// Created by vockey on 2020/8/21.
// Copyright © 2020 offcn. All rights reserved.
//
#import "OffcnUploadManager.h"
#import <QiniuSDK.h>
#import "QNTransactionManager.h"
#import "OffcnNetworkExecutor.h"
@interface OffcnUploadManager ()
@property (nonatomic, strong) QNUploadManager *upManager;
@property (nonatomic, strong) NSString *QNToken;
@end
@implementation OffcnUploadManager
static OffcnUploadManager *uploadManager;
+(OffcnUploadManager *)defaultService{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
uploadManager = [[OffcnUploadManager alloc] init];
});
return uploadManager;
}
-(instancetype)init{
self = [super init];
if (self) {
self.upManager = [[QNUploadManager alloc] init];
}
return self;
}
-(void)uploadToQNFileData:(NSData *)fileData Finished:(void(^)(BOOL success,id response,NSString *errorMessage))finished{
__weak typeof(self) weakSelf = self;
if (self.QNToken) {
[self uploadToQNWithQNToken:self.QNToken fileData:fileData Finished:^(BOOL success, id response, NSString *errorMessage) {
finished(success,response,errorMessage);
}];
}else{
[self getQNTokenFinished:^(BOOL success, NSString *errorMessage) {
if (success) {
[weakSelf uploadToQNWithQNToken:weakSelf.QNToken fileData:fileData Finished:^(BOOL success, id response, NSString *errorMessage) {
finished(success,response,errorMessage);
}];
}else{
finished(NO,nil,errorMessage);
}
}];
}
}
-(void)getQNTokenFinished:(void(^)(BOOL success,NSString *errorMessage))finished{
__weak typeof(self) weakSelf = self;
[OffcnNetworkExecutor requestUploadTokenFinished:^(BOOL success, id response, BaseResponse *baseResponse) {
if (success) {
NSString *token = [NSString stringWithFormat:@"%@",response];
weakSelf.QNToken = token;
NSLog(@"七牛token---%@",token);
finished(YES,nil);
}else{
finished(NO,@"获取token失败");
}
}];
}
-(void)uploadToQNWithQNToken:(NSString *)QNToken fileData:(NSData *)fileData Finished:(void(^)(BOOL success,id response,NSString *errorMessage))finished{
QNUploadOption *uploadOption = [[QNUploadOption alloc] initWithMime:nil progressHandler:^(NSString *key, float percent) {
NSLog(@"percent == %.2f", percent);
}params:nil checkCrc:NO cancellationSignal:nil];
[self.upManager putData:fileData key:nil token:QNToken complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
NSLog(@"info ===== %@", info);
NSLog(@"key ===== %@", key);
NSLog(@"resp ===== %@", resp);
if (resp) {
//发送消息
NSString *dataStr = [NSString stringWithFormat:@"http://test-offcncloud-im.eoffcn.com/%@",resp[@"key"]];
finished(YES,dataStr,nil);
}else{
finished(NO,nil,@"上传失败");
}
}option:uploadOption];
}
@end
...@@ -8,11 +8,10 @@ ...@@ -8,11 +8,10 @@
#import "ViewController.h" #import "ViewController.h"
#import "OffcnIMSDKiOS.h" #import "OffcnIMSDKiOS.h"
#import "OffcnNetworkExecutor.h" #import "OffcnNetworkExecutor.h"
#import <oimcore/oimcoreAdapter.h>
#import <QiniuSDK.h> #import <oimcore/oimcoreAdapter.h>
#import "QNTransactionManager.h"
@interface ViewController ()<OIMCoreDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate> @interface ViewController ()<OIMCoreDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>
...@@ -21,12 +20,9 @@ ...@@ -21,12 +20,9 @@
@property (strong, nonatomic) NSString *fromId; @property (strong, nonatomic) NSString *fromId;
@property (strong, nonatomic) NSString *toId; @property (strong, nonatomic) NSString *toId;
@property (assign, nonatomic) OffcnSDKMsgType msg_type;
@property (strong, nonatomic) NSMutableDictionary *dataDic;
@property (strong, nonatomic) OIMCoreAdapter *adapter; @property (strong, nonatomic) OIMCoreAdapter *adapter;
@property (nonatomic, strong) NSString *QNToken;
@property (nonatomic, strong) UIImage *pickImage; @property (nonatomic, strong) UIImage *pickImage;
@property (weak, nonatomic) IBOutlet UIImageView *showImage; @property (weak, nonatomic) IBOutlet UIImageView *showImage;
@end @end
...@@ -88,7 +84,7 @@ ...@@ -88,7 +84,7 @@
- (IBAction)sendMeg:(UIButton *)sender { - (IBAction)sendMeg:(UIButton *)sender {
//发送消息 //发送消息
[OffcnNetworkExecutor requestSendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:self.msg_type msg:self.dataDic Finished:^(BOOL success, id response, BaseResponse *baseResponse) { [[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:OffcnSDKMsgTypeText text:@"你好" fileData:nil Finished:^(BOOL success, id response, NSString *errorMessage) {
}]; }];
} }
...@@ -136,34 +132,10 @@ ...@@ -136,34 +132,10 @@
- (IBAction)uploadFile:(UIButton *)sender { - (IBAction)uploadFile:(UIButton *)sender {
//上传 //上传
__weak typeof(self) weakSelf = self; NSData *imageData = UIImageJPEGRepresentation(self.pickImage, 0.5);
[OffcnNetworkExecutor requestUploadTokenFinished:^(BOOL success, id response, BaseResponse *baseResponse) { [[OffcnIMSDKiOS defaultService] sendMsgWithMsg_fromID:self.fromId msg_toID:self.toId msg_type:OffcnSDKMsgTypePicture text:nil fileData:imageData Finished:^(BOOL success, id response, NSString *errorMessage) {
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 { - (void)viewDidLoad {
...@@ -173,10 +145,8 @@ ...@@ -173,10 +145,8 @@
self.changeEnvironmentBtn.selected = [OffcnIMSDKiOS defaultService].isTest; self.changeEnvironmentBtn.selected = [OffcnIMSDKiOS defaultService].isTest;
self.toId = @"ce0819db8391f1e7258a71cc9e2c3235";
self.fromId = @"jfdfjei0343"; self.fromId = @"jfdfjei0343";
self.msg_type = OffcnSDKMsgTypeText; self.toId = @"ce0819db8391f1e7258a71cc9e2c3235";
self.dataDic = [NSMutableDictionary dictionaryWithObject:@"我是一只小青龙" forKey:@"msg"];
} }
#pragma mark UIImagePickerControllerDelegate #pragma mark UIImagePickerControllerDelegate
......
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