Skip to content

Commit

Permalink
fixed for 10.2-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
namo-py committed Sep 3, 2018
1 parent 09550e3 commit dd447af
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
2 changes: 1 addition & 1 deletion SBFileStreamer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "SBFileStreamer"
s.version = "1.3.1"
s.version = "1.3.2"
s.summary = "Basic file streamer for iOS development."
s.description = "Basic file streamer for Objc.Inc iOS Developers, such as ViewController/View etc."

Expand Down
7 changes: 1 addition & 6 deletions SBFileStreamer/SBFileStreamer/SBFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,10 @@ typedef enum : NSUInteger {
@property (nonatomic, assign) NSUInteger totalLength;
@property (nonatomic, assign) NSUInteger currentLength;

/**
传输进度回调(weak file obj)
*/
@property (nonatomic, copy) void(^_Nullable progressCallback)(SBFile *_Nonnull) NS_UNAVAILABLE;

/**
传输状态回调(weak file obj)
*/
@property (nonatomic, copy) void(^_Nullable stateCallback)(SBFile *_Nonnull);
@property (nonatomic, copy, nullable) void(^_Nullable callback)(void);

//失败 or 成功
@property (nonatomic, strong, nullable) NSError *error;
Expand Down
22 changes: 10 additions & 12 deletions SBFileStreamer/SBFileStreamer/SBFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,9 @@ + (NSArray *)whc_IgnorePropertys {
@"ossTask",
@"manager",
@"progress",
@"callback",
@"fileHandler",
@"currentLength",
@"stateCallback",
@"progressCallback"];
@"currentLength"];
}

+ (NSString *)whc_SqliteVersion {
Expand Down Expand Up @@ -190,8 +189,8 @@ - (NSURLSessionDataTask *)fetchTask {
//callback
this.error = error;
this.state = (error == nil) ? SBFileStateFinished : SBFileStateFailed;
if (this.stateCallback) {
this.stateCallback(this);
if (this.callback) {
this.callback();
}
}];
//response callback
Expand All @@ -202,8 +201,8 @@ - (NSURLSessionDataTask *)fetchTask {
NSLog(@"file total size:%zd", this.totalLength);
//callback
this.state = SBFileStateInTransit;
if (this.stateCallback) {
this.stateCallback(this);
if (this.callback) {
this.callback();
}
return NSURLSessionResponseAllow;
}];
Expand All @@ -223,8 +222,8 @@ - (NSURLSessionDataTask *)fetchTask {
NSLog(@"percenter:%.2f", percent);
if (this.state != SBFileStateInTransit) {
this.state = SBFileStateInTransit;
if (this.stateCallback) {
this.stateCallback(this);
if (this.callback) {
this.callback();
}
}
}];
Expand All @@ -237,9 +236,8 @@ - (NSURLSessionDataTask *)fetchTask {
*/
- (void)resume:(BOOL)r {
self.state = r ? SBFileStateInTransit : SBFileStatePause;
if (self.stateCallback) {
__weak typeof (self) this = self;
self.stateCallback(this);
if (self.callback) {
self.callback();
}
if (r) {
[self.task resume];
Expand Down
34 changes: 20 additions & 14 deletions SBFileStreamer/SBFileStreamer/SBFileStreamer.m
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ - (void)append2Download:(NSArray<SBFile *> *)files {
//callback
for (SBFile *f in files) {
__weak typeof (self) this = self;
f.stateCallback = ^(SBFile *f){
[this updateState:f];
// f.stateCallback = ^(SBFile *f){
// [this updateState:f];
// };
__weak typeof(SBFile)*wkFile = f;
f.callback = ^{
[this updateState:wkFile];
};
//存储
NSString *sql = [NSString stringWithFormat:@"key = '%@' AND owner = '%@'", f.key, f.owner];
Expand All @@ -90,20 +94,22 @@ - (void)updateState:(SBFile *)f {
NSString *where = [NSString stringWithFormat:@"key = '%@' AND owner = '%@'", f.key, f.owner];
[WHCSqlite update:[SBFile class] value:value where:where];

//是否继续下一个
SBFileState shouldState = (SBFileStateFinished | SBFileStateFailed | SBFileStatePause);
if (f.state & shouldState) {
[self next];
}
//移除队列
if (f.state & (SBFileStateFinished | SBFileStateFailed)) {
@synchronized(self.downloadQueues){
[self.downloadQueues enumerateObjectsUsingBlock:^(SBFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.key == f.key) {
[self.downloadQueues removeObject:obj];
*stop = true;
}
}];
}
[self next];
} else if (f.state & SBFileStatePause) {
//暂定后继续下一个
[self next];
// @synchronized(self.downloadQueues){
// [self.downloadQueues enumerateObjectsUsingBlock:^(SBFile * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
// if (obj.key == f.key) {
// [self.downloadQueues removeObject:obj];
// *stop = true;
// }
// }];
// }
// [self next];
}
}

Expand Down
4 changes: 2 additions & 2 deletions SBFileStreamer/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ - (void)testDownload {
// NSString *key = @"100MB-tokyo.bin";
// NSString *owner = @"nanhujiaju";

NSString *uri = @"http://7xrm04.com2.z0.glb.qiniucdn.com/3bfe46c3621abf2bc89f50969a74c9a2.lrc";
NSString *key = @"3bfe46c3621abf2bc89f50969a74c9a2.lrc";
NSString *uri = @"http://7xrm04.com2.z0.glb.qiniucdn.com/http://qukufile2.qianqian.com/data2/lrc/19dd692032af6bd72460fdf3b4cfe624/598760621/598760621.lrc";
NSString *key = @"http://qukufile2.qianqian.com/data2/lrc/19dd692032af6bd72460fdf3b4cfe624/598760621/598760621.lrc";
NSString *owner = @"nanhujiaju";

SBFile *file = [SBFile fileWithUri:uri key:key storage:SBFileCloudQiNiu owner:owner];
Expand Down

0 comments on commit dd447af

Please sign in to comment.