Skip to content

Commit 09fd0ce

Browse files
committed
conflict
2 parents d168b0c + 8e64e1a commit 09fd0ce

File tree

14 files changed

+378
-68
lines changed

14 files changed

+378
-68
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#Changelog
22

3-
## 7.0.13 (2015-10-20)
3+
## 7.0.13 (2015-10-28)
44

55
### 增加
6-
* 支持 https
76
* 禁止0字节文件上传
87
* ua加入idfv 便于网络诊断
8+
* 支持PHAsset
99

1010
### 修正
11+
* HappyDns swift bridge问题
1112
* QNHttpDelegate.h 头文件名大小写修正
1213
* 指定AFNetworking 为2.5.+, 因为2.6已经移除iOS 6 支持
1314
* 变更set host 方法

QiniuSDK.xcodeproj/project.pbxproj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
BA1659321BDBD6FB00C7304A /* QNStats.m in Sources */ = {isa = PBXBuildFile; fileRef = BA16592F1BDBD6FB00C7304A /* QNStats.m */; settings = {ASSET_TAGS = (); }; };
1717
BA8408531BE250C80093B013 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA8408521BE250C80093B013 /* SystemConfiguration.framework */; };
1818
BA8408541BE251010093B013 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BA8408521BE250C80093B013 /* SystemConfiguration.framework */; };
19+
93CEF47E1BDE11FF00750FE8 /* QNPHAssetFile.h in Headers */ = {isa = PBXBuildFile; fileRef = 93CEF47C1BDE11FF00750FE8 /* QNPHAssetFile.h */; settings = {ASSET_TAGS = (); }; };
20+
93CEF47F1BDE11FF00750FE8 /* QNPHAssetFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CEF47D1BDE11FF00750FE8 /* QNPHAssetFile.m */; settings = {ASSET_TAGS = (); }; };
21+
93CEF4801BDE11FF00750FE8 /* QNPHAssetFile.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CEF47D1BDE11FF00750FE8 /* QNPHAssetFile.m */; settings = {ASSET_TAGS = (); }; };
1922
DF0A03231B3BABEC00E3778C /* libQiniuSDK Mac.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = DF2CDDFF19DAC05500CE01FB /* libQiniuSDK Mac.dylib */; };
2023
DF0A03241B3BAC3900E3778C /* QNFormUploadTest.m in Sources */ = {isa = PBXBuildFile; fileRef = DF3C504619DD7BA6000F548F /* QNFormUploadTest.m */; };
2124
DF0A03251B3BAC5700E3778C /* libQiniuSDK iOS.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DF2CDE1A19DAC08400CE01FB /* libQiniuSDK iOS.a */; };
@@ -132,6 +135,8 @@
132135
75127E9F1F2BA68C9D5B463F /* Pods-QiniuSDK iOS.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK iOS.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK iOS/Pods-QiniuSDK iOS.release.xcconfig"; sourceTree = "<group>"; };
133136
7EFD2A2AD31548D6BD3FD007 /* Pods-QiniuSDK MacTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK MacTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK MacTests/Pods-QiniuSDK MacTests.release.xcconfig"; sourceTree = "<group>"; };
134137
8924D07F6E137C6379C173D4 /* libPods-QiniuSDK Mac.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-QiniuSDK Mac.a"; sourceTree = BUILT_PRODUCTS_DIR; };
138+
93CEF47C1BDE11FF00750FE8 /* QNPHAssetFile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QNPHAssetFile.h; sourceTree = "<group>"; };
139+
93CEF47D1BDE11FF00750FE8 /* QNPHAssetFile.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QNPHAssetFile.m; sourceTree = "<group>"; };
135140
948F5D59B2BD6CACC644FA14 /* Pods-QiniuSDK MacTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK MacTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK MacTests/Pods-QiniuSDK MacTests.debug.xcconfig"; sourceTree = "<group>"; };
136141
9A0CE9E3B1F13E790C38CB75 /* Pods-QiniuSDK iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-QiniuSDK iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-QiniuSDK iOSTests/Pods-QiniuSDK iOSTests.release.xcconfig"; sourceTree = "<group>"; };
137142
BA0FAD4A1BE25EE500DD5C51 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = "<group>"; };
@@ -366,6 +371,8 @@
366371
DFF126F01B639F3B0005C39C /* QNFile.m */,
367372
DFF126F41B63ABED0005C39C /* QNALAssetFile.h */,
368373
DFF126F51B63ABED0005C39C /* QNALAssetFile.m */,
374+
93CEF47C1BDE11FF00750FE8 /* QNPHAssetFile.h */,
375+
93CEF47D1BDE11FF00750FE8 /* QNPHAssetFile.m */,
369376
DFBF636D1BCCE28200A771D8 /* QNSystem.m */,
370377
DFBF63701BCCE2A600A771D8 /* QNSystem.h */,
371378
);
@@ -443,6 +450,7 @@
443450
DF482FD81B0DA8A2000DAD98 /* QNConfiguration.h in Headers */,
444451
DF609A051A58E39D00AC7297 /* QNFormUpload.h in Headers */,
445452
DFF525371A626A3700D02BA1 /* QNHttpDelegate.h in Headers */,
453+
93CEF47E1BDE11FF00750FE8 /* QNPHAssetFile.h in Headers */,
446454
DF2CDE6019DAC6A400CE01FB /* QNCrc32.h in Headers */,
447455
DFF126F11B639F3B0005C39C /* QNFile.h in Headers */,
448456
DFA9B63B19DF904000A15FD1 /* QNEtag.h in Headers */,
@@ -734,6 +742,7 @@
734742
DF293C9F19DBC2AE00799011 /* QNUserAgent.m in Sources */,
735743
BA1659311BDBD6FB00C7304A /* QNStats.m in Sources */,
736744
DFA9B65919E0B53700A15FD1 /* QNFileRecorder.m in Sources */,
745+
93CEF47F1BDE11FF00750FE8 /* QNPHAssetFile.m in Sources */,
737746
DF2CDE6119DAC6A400CE01FB /* QNCrc32.m in Sources */,
738747
DF293CA619DC05B800799011 /* QNHttpManager.m in Sources */,
739748
DF293CAB19DC0E5300799011 /* QNResumeUpload.m in Sources */,
@@ -780,6 +789,7 @@
780789
DF482FDA1B0DA8A2000DAD98 /* QNConfiguration.m in Sources */,
781790
BA1659321BDBD6FB00C7304A /* QNStats.m in Sources */,
782791
DF609A081A58E39D00AC7297 /* QNFormUpload.m in Sources */,
792+
93CEF4801BDE11FF00750FE8 /* QNPHAssetFile.m in Sources */,
783793
DF293CA019DBC2AE00799011 /* QNUserAgent.m in Sources */,
784794
DFA9B65A19E0B53700A15FD1 /* QNFileRecorder.m in Sources */,
785795
DF2CDE6219DAC6A400CE01FB /* QNCrc32.m in Sources */,
@@ -849,7 +859,8 @@
849859
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
850860
GCC_WARN_UNUSED_FUNCTION = YES;
851861
GCC_WARN_UNUSED_VARIABLE = YES;
852-
MACOSX_DEPLOYMENT_TARGET = 10.10;
862+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
863+
MACOSX_DEPLOYMENT_TARGET = 10.9;
853864
MTL_ENABLE_DEBUG_INFO = YES;
854865
ONLY_ACTIVE_ARCH = YES;
855866
SDKROOT = macosx;
@@ -884,7 +895,8 @@
884895
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
885896
GCC_WARN_UNUSED_FUNCTION = YES;
886897
GCC_WARN_UNUSED_VARIABLE = YES;
887-
MACOSX_DEPLOYMENT_TARGET = 10.10;
898+
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
899+
MACOSX_DEPLOYMENT_TARGET = 10.9;
888900
MTL_ENABLE_DEBUG_INFO = NO;
889901
SDKROOT = macosx;
890902
};

QiniuSDK/Common/QNPHAssetFile.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// QNPHAssetFile.h
3+
// Pods
4+
//
5+
// Created by 何舒 on 15/10/21.
6+
//
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
#import "QNFileDelegate.h"
12+
13+
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000)
14+
@class PHAsset;
15+
@interface QNPHAssetFile : NSObject<QNFileDelegate>
16+
/**
17+
* 打开指定文件
18+
*
19+
* @param path 文件路径
20+
* @param error 输出的错误信息
21+
*
22+
* @return 实例
23+
*/
24+
- (instancetype)init:(PHAsset *)phAsset
25+
error:(NSError *__autoreleasing *)error;
26+
@end
27+
#endif

QiniuSDK/Common/QNPHAssetFile.m

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
//
2+
// QNPHAssetFile.m
3+
// Pods
4+
//
5+
// Created by 何舒 on 15/10/21.
6+
//
7+
//
8+
9+
#import "QNPHAssetFile.h"
10+
11+
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000)
12+
#import <Photos/Photos.h>
13+
#import <AVFoundation/AVFoundation.h>
14+
enum {
15+
kAMASSETMETADATA_PENDINGREADS = 1,
16+
kAMASSETMETADATA_ALLFINISHED = 0
17+
};
18+
19+
#import "QNResponseInfo.h"
20+
21+
@interface QNPHAssetFile ()
22+
{
23+
BOOL _hasGotInfo;
24+
}
25+
26+
@property (nonatomic) PHAsset * phAsset;
27+
28+
@property (readonly) int64_t fileSize;
29+
30+
@property (readonly) int64_t fileModifyTime;
31+
32+
@property (nonatomic, strong) NSData *assetData;
33+
34+
@property (nonatomic, strong) NSURL *assetURL;
35+
36+
@end
37+
38+
@implementation QNPHAssetFile
39+
40+
- (instancetype)init:(PHAsset *)phAsset error:(NSError *__autoreleasing *)error
41+
{
42+
if (self = [super init]) {
43+
NSDate *createTime = phAsset.creationDate;
44+
int64_t t = 0;
45+
if (createTime != nil) {
46+
t = [createTime timeIntervalSince1970];
47+
}
48+
_fileModifyTime = t;
49+
_phAsset = phAsset;
50+
[self getInfo];
51+
52+
}
53+
return self;
54+
}
55+
56+
- (NSData *)read:(long)offset size:(long)size
57+
{
58+
NSRange subRange = NSMakeRange(offset, size);
59+
if (!self.assetData) {
60+
self.assetData = [self fetchDataFromAsset:self.phAsset];
61+
}
62+
NSData *subData = [self.assetData subdataWithRange:subRange];
63+
64+
return subData;
65+
}
66+
67+
- (NSData *)readAll {
68+
return [self read:0 size:(long)_fileSize];
69+
}
70+
71+
- (void)close {
72+
}
73+
74+
-(NSString *)path {
75+
return self.assetURL.path;
76+
}
77+
78+
- (int64_t)modifyTime {
79+
return _fileModifyTime;
80+
}
81+
82+
- (int64_t)size {
83+
return _fileSize;
84+
}
85+
86+
- (void)getInfo
87+
{
88+
if (!_hasGotInfo) {
89+
_hasGotInfo = YES;
90+
91+
if (PHAssetMediaTypeImage == self.phAsset.mediaType) {
92+
PHImageRequestOptions *request = [PHImageRequestOptions new];
93+
request.version = PHImageRequestOptionsVersionCurrent;
94+
request.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
95+
request.resizeMode = PHImageRequestOptionsResizeModeNone;
96+
request.synchronous = YES;
97+
98+
[[PHImageManager defaultManager] requestImageDataForAsset:self.phAsset
99+
options:request
100+
resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
101+
_fileSize = imageData.length;
102+
_assetURL = [NSURL URLWithString:self.phAsset.localIdentifier];
103+
}
104+
];
105+
}
106+
else if (PHAssetMediaTypeVideo == self.phAsset.mediaType) {
107+
PHVideoRequestOptions *request = [PHVideoRequestOptions new];
108+
request.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
109+
request.version = PHVideoRequestOptionsVersionCurrent;
110+
111+
NSConditionLock* assetReadLock = [[NSConditionLock alloc] initWithCondition:kAMASSETMETADATA_PENDINGREADS];
112+
[[PHImageManager defaultManager] requestPlayerItemForVideo:self.phAsset options:request resultHandler:^(AVPlayerItem *playerItem, NSDictionary *info) {
113+
AVURLAsset *urlAsset = (AVURLAsset *)playerItem.asset;
114+
NSNumber *fileSize = nil;
115+
[urlAsset.URL getResourceValue:&fileSize forKey:NSURLFileSizeKey error:nil];
116+
_fileSize = [fileSize unsignedLongLongValue];
117+
_assetURL = urlAsset.URL;
118+
119+
[assetReadLock lock];
120+
[assetReadLock unlockWithCondition:kAMASSETMETADATA_ALLFINISHED];
121+
}];
122+
[assetReadLock lockWhenCondition:kAMASSETMETADATA_ALLFINISHED];
123+
[assetReadLock unlock];
124+
assetReadLock = nil;
125+
}
126+
}
127+
128+
}
129+
130+
- (NSData *)fetchDataFromAsset:(PHAsset *)asset
131+
{
132+
__block NSData *tmpData = [NSData data];
133+
134+
// Image
135+
if (asset.mediaType == PHAssetMediaTypeImage) {
136+
PHImageRequestOptions *request = [PHImageRequestOptions new];
137+
request.version = PHImageRequestOptionsVersionCurrent;
138+
request.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
139+
request.resizeMode = PHImageRequestOptionsResizeModeNone;
140+
request.synchronous = YES;
141+
142+
[[PHImageManager defaultManager] requestImageDataForAsset:asset
143+
options:request
144+
resultHandler:
145+
^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
146+
tmpData = [NSData dataWithData:imageData];
147+
}];
148+
}
149+
// Video
150+
else {
151+
152+
PHVideoRequestOptions *request = [PHVideoRequestOptions new];
153+
request.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
154+
request.version = PHVideoRequestOptionsVersionCurrent;
155+
156+
NSConditionLock *assetReadLock = [[NSConditionLock alloc] initWithCondition:kAMASSETMETADATA_PENDINGREADS];
157+
158+
159+
[[PHImageManager defaultManager] requestAVAssetForVideo:asset
160+
options:request
161+
resultHandler:
162+
^(AVAsset* asset, AVAudioMix* audioMix, NSDictionary* info) {
163+
AVURLAsset *urlAsset = (AVURLAsset *)asset;
164+
NSData *videoData = [NSData dataWithContentsOfURL:urlAsset.URL];
165+
tmpData = [NSData dataWithData:videoData];
166+
167+
[assetReadLock lock];
168+
[assetReadLock unlockWithCondition:kAMASSETMETADATA_ALLFINISHED];
169+
}];
170+
171+
[assetReadLock lockWhenCondition:kAMASSETMETADATA_ALLFINISHED];
172+
[assetReadLock unlock];
173+
assetReadLock = nil;
174+
}
175+
176+
return tmpData;
177+
}
178+
179+
@end
180+
#endif

QiniuSDK/Http/QNHttpManager.m

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#import "HappyDNS.h"
1717
#import "QNStats.h"
1818

19-
#import "QNSystem.h"
20-
2119
@interface QNHttpManager ()
2220
@property (nonatomic) AFHTTPRequestOperationManager *httpManager;
2321
@property UInt32 timeout;
@@ -229,7 +227,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
229227
url = [[NSURL alloc] initWithString:_converter(u)];
230228
request.URL = url;
231229
domain = url.host;
232-
}else if(_dns != nil /*&& [url.scheme isEqual: @"http"] && !hasAts()*/) {
230+
}else if(_dns != nil && [url.scheme isEqual: @"http"]){
233231
ips = [_dns queryWithDomain:[[QNDomain alloc] init:domain hostsFirst:NO hasCname:YES maxTtl:1000]];
234232
double duration = [[NSDate date] timeIntervalSinceDate:startTime];
235233
setStat(stats, @"dt", [NSNumber numberWithInt:(int)(duration*1000)]);
@@ -248,7 +246,6 @@ - (void) sendRequest:(NSMutableURLRequest *)request
248246
}
249247
}
250248
[self sendRequest2:request withStats:stats withCompleteBlock:completeBlock withProgressBlock:progressBlock withCancelBlock:cancelBlock withIpArray:ips withIndex:0 withDomain:domain withRetryTimes:kQNRetryConnectTimes withStartTime:startTime];
251-
252249
}
253250

254251
- (void) multipartPost:(NSString *)url

QiniuSDK/Http/QNSessionManager.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#import "QNStats.h"
1919
#import "QNSystem.h"
2020

21-
22-
2321
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090)
2422

2523
@interface QNProgessDelegate : NSObject
@@ -164,7 +162,7 @@ - (void) sendRequest:(NSMutableURLRequest *)request
164162
url = [[NSURL alloc] initWithString:_converter(u)];
165163
request.URL = url;
166164
domain = url.host;
167-
} else if (_noProxy && _dns != nil /*&& [url.scheme isEqualToString:@"http"] && !hasAts()*/) {
165+
} else if (_noProxy && _dns != nil && [url.scheme isEqualToString:@"http"]){
168166
ips = [_dns queryWithDomain:[[QNDomain alloc] init:domain hostsFirst:NO hasCname:YES maxTtl:1000]];
169167
double duration = [[NSDate date] timeIntervalSinceDate:startTime];
170168

QiniuSDK/Storage/QNConfiguration.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
7777

7878
@property (nonatomic, readonly) QNDnsManager *dns;
7979

80+
@property (readonly) BOOL disableATS;
81+
8082
+ (instancetype)build:(QNConfigurationBuilderBlock)block;
8183

8284
@end
@@ -172,4 +174,6 @@ typedef void (^QNConfigurationBuilderBlock)(QNConfigurationBuilder *builder);
172174

173175
@property (nonatomic, assign) QNDnsManager *dns;
174176

177+
@property (assign) BOOL disableATS;
178+
175179
@end

QiniuSDK/Storage/QNConfiguration.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#import "QNNetworkInfo.h"
1111
#import "HappyDNS.h"
1212

13+
#import "QNSystem.h"
14+
1315
const UInt32 kQNBlockSize = 4 * 1024 * 1024;
1416

1517
static void addServiceToDns(QNServiceAddress* address, QNDnsManager *dns) {
@@ -69,8 +71,13 @@ - (instancetype)initWithBuilder:(QNConfigurationBuilder *)builder {
6971

7072
_converter = builder.converter;
7173

72-
_dns = initDns(builder);
73-
addZoneToDns(builder.zone, _dns);
74+
_disableATS = builder.disableATS;
75+
if (_disableATS || !hasAts()) {
76+
_dns = initDns(builder);
77+
addZoneToDns(builder.zone, _dns);
78+
}else{
79+
_dns = nil;
80+
}
7481
}
7582
return self;
7683
}
@@ -93,6 +100,7 @@ - (instancetype)init {
93100
_proxy = nil;
94101
_converter = nil;
95102

103+
_disableATS = YES;
96104
}
97105
return self;
98106
}

0 commit comments

Comments
 (0)