Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ios
/
yh_sdwebimage
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
DreamPiggy
7 years ago
Commit
3b4dd0b184edb67201b4695b3348cf7c496b690a
1 parent
9c7224fd
Add a convenience method to allow cancel on downloadToken
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
1 deletions
SDWebImage/SDWebImageDownloader.h
SDWebImage/SDWebImageDownloader.m
SDWebImage/SDWebImageDownloaderOperation.h
SDWebImage/SDWebImageDownloader.h
View file @
3b4dd0b
...
...
@@ -82,9 +82,16 @@ typedef SDHTTPHeadersDictionary * _Nullable (^SDWebImageDownloaderHeadersFilterB
/**
* A token associated with each download. Can be used to cancel a download
*/
@interface
SDWebImageDownloadToken
:
NSObject
@interface
SDWebImageDownloadToken
:
NSObject
<
SDWebImageOperation
>
/**
The download's URL. This should be readonly and you should not modify
*/
@property
(
nonatomic
,
strong
,
nullable
)
NSURL
*
url
;
/**
The cancel token taken from `addHandlersForProgress:completed`. This should be readonly and you should not modify
@note use `-[SDWebImageDownloadToken cancel]` to cancel the token
*/
@property
(
nonatomic
,
strong
,
nullable
)
id
downloadOperationCancelToken
;
@end
...
...
SDWebImage/SDWebImageDownloader.m
View file @
3b4dd0b
...
...
@@ -9,7 +9,23 @@
#import "SDWebImageDownloader.h"
#import "SDWebImageDownloaderOperation.h"
@interface
SDWebImageDownloadToken
()
@property
(
nonatomic
,
weak
,
nullable
)
NSOperation
<
SDWebImageDownloaderOperationInterface
>
*
downloadOperation
;
@end
@implementation
SDWebImageDownloadToken
-
(
void
)
cancel
{
if
(
self
.
downloadOperation
)
{
SDWebImageDownloadToken
*
cancelToken
=
self
.
downloadOperationCancelToken
;
if
(
cancelToken
)
{
[
self
.
downloadOperation
cancel
:
cancelToken
];
}
}
}
@end
...
...
@@ -258,6 +274,7 @@
id
downloadOperationCancelToken
=
[
operation
addHandlersForProgress
:
progressBlock
completed
:
completedBlock
];
token
=
[
SDWebImageDownloadToken
new
];
token
.
downloadOperation
=
operation
;
token
.
url
=
url
;
token
.
downloadOperationCancelToken
=
downloadOperationCancelToken
;
});
...
...
SDWebImage/SDWebImageDownloaderOperation.h
View file @
3b4dd0b
...
...
@@ -19,6 +19,7 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification
/**
Describes a downloader operation. If one wants to use a custom downloader op, it needs to inherit from `NSOperation` and conform to this protocol
For the description about these methods, see `SDWebImageDownloaderOperation`
*/
@protocol
SDWebImageDownloaderOperationInterface
<
NSObject
>
...
...
@@ -35,6 +36,8 @@ FOUNDATION_EXPORT NSString * _Nonnull const SDWebImageDownloadFinishNotification
-
(
nullable
NSURLCredential
*
)
credential
;
-
(
void
)
setCredential
:(
nullable
NSURLCredential
*
)
value
;
-
(
BOOL
)
cancel
:(
nullable
id
)
token
;
@end
...
...
Please
register
or
login
to post a comment