Skip to content

Commit a2b46de

Browse files
author
karisli
committed
QCloudQuic发布
1 parent 7e639f8 commit a2b46de

22 files changed

+1038
-0
lines changed

QCloudQuic.podspec

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Be sure to run `pod lib lint QCloudQuic.podspec' to ensure this is a
3+
# valid spec before submitting.
4+
#
5+
# Any lines starting with a # are optional, but their use is encouraged
6+
# To learn more about a Podspec see http://guides.cocoapods.org/syntax/podspec.html
7+
#
8+
9+
Pod::Spec.new do |s|
10+
s.name = "QCloudQuic"
11+
s.version = "0.1.0"
12+
s.summary = "QCloudQuic 腾讯云iOS-SDK组件"
13+
14+
# This description is used to generate tags and improve search results.
15+
# * Think: What does it do? Why did you write it? What is the focus?
16+
# * Try to keep it short, snappy and to the point.
17+
# * Write the description between the DESC delimiters below.
18+
# * Finally, don't worry about the indent, CocoaPods strips it!
19+
20+
s.description = <<-DESC
21+
TODO: Add long description of the pod here.aaa
22+
DESC
23+
24+
s.homepage = "https://cloud.tencent.com/"
25+
# s.screenshots = "www.example.com/screenshots_1", "www.example.com/screenshots_2"
26+
s.license = 'MIT'
27+
s.author = { "QCloudTerminalLab" => "[email protected]" }
28+
s.source = { :git => "https://github.com/tencentyun/qcloud-sdk-ios.git", :tag => s.version.to_s }
29+
# s.social_media_url = 'https://twitter.com/<TWITTER_USERNAME>'
30+
s.ios.deployment_target = '8.0'
31+
s.source_files = 'Pod/Classes/QCloudBase/**/*','Pod/Classes/QuicFramework//*.{h}'
32+
s.vendored_frameworks = 'Pod/Classes/QuicFramework/Tquic.framework'
33+
# s.public_header_files = 'Pod/Classes/**/*.h'
34+
# s.frameworks = 'UIKit', 'MapKit'
35+
# s.dependency 'AFNetworking', '~> 2.3'
36+
s.static_framework = true
37+
38+
39+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// QCloudQuic.h
3+
// <POD_NAME
4+
//
5+
// Created by tencent
6+
//
7+
// QCloudTerminalLab --- service for developers
8+
9+
10+
11+
12+
13+
#import <Foundation/Foundation.h>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// QCloudQuicDataTask.h
3+
// QCloudCore
4+
//
5+
// Created by karisli(李雪) on 2019/3/22.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
@class QCloudQuicSession;
10+
11+
NS_ASSUME_NONNULL_BEGIN
12+
13+
@interface QCloudQuicDataTask<BodyType> : NSURLSessionDataTask
14+
@property (nonatomic, weak) id<NSURLSessionDataDelegate> delegate;
15+
@property (nullable, readwrite, copy) NSHTTPURLResponse *response;
16+
@property (nullable, readwrite, copy) NSURLRequest *originalRequest;
17+
18+
@property (nonatomic, strong) id manager;
19+
- (instancetype)initWithHTTPRequest:(NSMutableURLRequest *)httpRequest
20+
quicHost:(NSString *)quicHost
21+
quicIp:(NSString *)quicIp
22+
body:(BodyType)body
23+
quicSession:(QCloudQuicSession *)quicSession;
24+
- (void)start;
25+
@end
26+
27+
NS_ASSUME_NONNULL_END
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
//
2+
// QCloudQuicDataTask.m
3+
// QCloudCore
4+
//
5+
// Created by karisli(李雪) on 2019/3/22.
6+
//
7+
8+
#import "QCloudQuicDataTask.h"
9+
#import "QCloudQuicSession.h"
10+
#import "Tquicnet.h"
11+
12+
@implementation QCloudQuicDataTask
13+
@synthesize response = _response;
14+
@synthesize originalRequest = _originalRequest;
15+
16+
- (instancetype)initWithHTTPRequest:(NSMutableURLRequest *)httpRequest
17+
quicHost:(NSString *)quicHost
18+
quicIp:(NSString *)quicIp
19+
body:(id)body
20+
quicSession:(QCloudQuicSession *)quicSession {
21+
if (self = [super init]) {
22+
id bodyData = nil;
23+
if (body && !(body == [NSNull null])) {
24+
bodyData = body;
25+
} else if (httpRequest.HTTPBody) {
26+
bodyData = httpRequest.HTTPBody;
27+
}
28+
TquicRequest *req = [[TquicRequest alloc] initWithURL:httpRequest.URL
29+
host:quicHost
30+
httpMethod:httpRequest.HTTPMethod
31+
ip:quicIp
32+
body:bodyData
33+
headerFileds:httpRequest.allHTTPHeaderFields];
34+
_manager = [TquicConnection new];
35+
__weak typeof(self) weakSelf = self;
36+
[_manager tquicConnectWithQuicRequest:req
37+
didReceiveResponse:^(TquicResponse *_Nonnull response) {
38+
__strong typeof(weakSelf) strngSelf = weakSelf;
39+
strngSelf.response = [[NSHTTPURLResponse alloc] initWithURL:httpRequest.URL
40+
statusCode:response.statusCode
41+
HTTPVersion:response.httpVersion
42+
headerFields:[response.allHeaderFields copy]];
43+
if ([strngSelf.delegate respondsToSelector:@selector(URLSession:dataTask:didReceiveResponse:completionHandler:)]) {
44+
[strngSelf.delegate URLSession:quicSession dataTask:strngSelf didReceiveResponse:strngSelf.response completionHandler:nil];
45+
}
46+
}
47+
didReceiveData:^(NSData *_Nonnull data) {
48+
__strong typeof(weakSelf) strngSelf = weakSelf;
49+
if ([strngSelf.delegate respondsToSelector:@selector(URLSession:dataTask:didReceiveData:)]) {
50+
[strngSelf.delegate URLSession:quicSession dataTask:strngSelf didReceiveData:data];
51+
}
52+
}
53+
didSendBodyData:^(int64_t bytesSent, int64_t totolSentBytes, int64_t totalBytesExpectedToSend) {
54+
__strong typeof(weakSelf) strngSelf = weakSelf;
55+
if ([strngSelf.delegate respondsToSelector:@selector(URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:)]) {
56+
[strngSelf.delegate URLSession:quicSession
57+
task:strngSelf
58+
didSendBodyData:bytesSent
59+
totalBytesSent:totolSentBytes
60+
totalBytesExpectedToSend:totalBytesExpectedToSend];
61+
}
62+
}
63+
RequestDidCompleteWithError:^(NSError *_Nonnull error) {
64+
__strong typeof(weakSelf) strngSelf = weakSelf;
65+
strngSelf.originalRequest = [[NSURLRequest alloc] initWithURL:httpRequest.URL];
66+
if ([strngSelf.delegate respondsToSelector:@selector(URLSession:task:didCompleteWithError:)]) {
67+
[strngSelf.delegate URLSession:quicSession task:strngSelf didCompleteWithError:error];
68+
}
69+
}];
70+
}
71+
return self;
72+
}
73+
- (void)setResponse:(NSHTTPURLResponse *)response {
74+
_response = response;
75+
}
76+
- (NSHTTPURLResponse *)response {
77+
return _response;
78+
}
79+
80+
- (NSURLRequest *)currentRequest {
81+
return _originalRequest;
82+
}
83+
84+
- (void)setOriginalRequest:(NSURLRequest *)originalRequest {
85+
_originalRequest = originalRequest;
86+
}
87+
- (NSURLRequest *)originalRequest {
88+
return _originalRequest;
89+
}
90+
- (void)cancel {
91+
[_manager cancleRequest];
92+
}
93+
- (void)start {
94+
[_manager startRequest];
95+
}
96+
- (void)dealloc {
97+
// _manager = nil;
98+
NSLog(@"QCloudQuicDataTask dealloc");
99+
}
100+
101+
@end
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// QCloudQuicSession.h
3+
// QCloudCore
4+
//
5+
// Created by karisli(李雪) on 2019/3/22.
6+
//
7+
8+
#import <Foundation/Foundation.h>
9+
10+
@class QCloudQuicDataTask;
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
@interface QCloudQuicSession<BodyType> : NSURLSession
15+
16+
+ (instancetype)quicSessionDelegate:(nullable id<NSURLSessionDataDelegate>)delegate;
17+
@property (nullable, readonly, retain) id<NSURLSessionDataDelegate> delegate;
18+
- (QCloudQuicDataTask *)quicDataTaskWithRequst:(NSMutableURLRequest *)httpRequs infos:(NSDictionary *)dic;
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//
2+
// QCloudQuicSession.m
3+
// QCloudCore
4+
//
5+
// Created by karisli(李雪) on 2019/3/22.
6+
//
7+
8+
#import "QCloudQuicSession.h"
9+
#import "QCloudQuicDataTask.h"
10+
@interface QCloudQuicSession ()
11+
12+
@end
13+
static QCloudQuicSession *quicSession;
14+
id<NSURLSessionDataDelegate> quicDelegate;
15+
@implementation QCloudQuicSession
16+
+ (instancetype)quicSessionDelegate:(id<NSURLSessionDataDelegate>)delegate {
17+
static dispatch_once_t onceToken;
18+
dispatch_once(&onceToken, ^{
19+
quicSession = [[QCloudQuicSession alloc] init];
20+
21+
quicDelegate = delegate;
22+
});
23+
return quicSession;
24+
}
25+
- (QCloudQuicDataTask *)quicDataTaskWithRequst:(NSMutableURLRequest *)httpRequst infos:(NSDictionary *)dic {
26+
id body = dic[@"body"];
27+
NSString *quicHost = dic[@"quicHost"];
28+
NSString *quicIp = dic[@"quicIP"];
29+
30+
QCloudQuicDataTask *quicTask = [[QCloudQuicDataTask alloc] initWithHTTPRequest:httpRequst
31+
quicHost:quicHost
32+
quicIp:quicIp
33+
body:body
34+
quicSession:self];
35+
quicTask.delegate = quicDelegate;
36+
return quicTask;
37+
}
38+
@end
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// TquicRequest.h
3+
// Tquic
4+
//
5+
// Created by karisli(李雪) on 2019/3/18.
6+
// Copyright © 2019 tencentyun.com. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@class TquicRequest;
12+
@class TquicResponse;
13+
NS_ASSUME_NONNULL_BEGIN
14+
typedef void (^TquicRequestDidConnectBlock)(BOOL sucessed);
15+
typedef void (^TquicRequesDidReceiveResponseBlock)(TquicResponse *response);
16+
17+
typedef void (^TquicRequestDidReceiveDataBlock)(NSData *data);
18+
typedef void (^TquicRequestDidSendBodyDataBlock)(int64_t bytesSent, int64_t totolSentBytes, int64_t totalBytesExpectedToSend);
19+
typedef void (^TquicRequesDidCompleteWithErrorBlock)(NSError *error);
20+
@interface TquicConnection : NSObject
21+
22+
@property (nonatomic, assign) BOOL connect;
23+
- (void)tquicConnectWithQuicRequest:(TquicRequest *)quicRequest
24+
didReceiveResponse:(TquicRequesDidReceiveResponseBlock)didReceiveResponse
25+
didReceiveData:(TquicRequestDidReceiveDataBlock)didReceiveData
26+
didSendBodyData:(TquicRequestDidSendBodyDataBlock)didSendBodyData
27+
RequestDidCompleteWithError:(TquicRequesDidCompleteWithErrorBlock)requestDidCompleteWithError;
28+
- (void)cancleRequest;
29+
- (void)startRequest;
30+
31+
@end
32+
33+
NS_ASSUME_NONNULL_END

0 commit comments

Comments
 (0)