Created
January 8, 2020 02:15
-
-
Save Gandum2077/e2a3e830d38e0ab2583e8a6225c900fd to your computer and use it in GitHub Desktop.
Using SDWebImageManager in JSBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const manager = $objc("SDWebImageManager").$sharedManager(); | |
| const url = $objc("NSURL").$URLWithString(""); | |
| const options = 0; | |
| const modifier = $objc("SDWebImageDownloaderRequestModifier").$requestModifierWithBlock($block("NSURLRequest *, NSURLRequest *", request => { | |
| const mutableRequest = request.$mutableCopy(); | |
| mutableRequest.$setValue_forHTTPHeaderField("value", "key"); | |
| return mutableRequest.$copy(); | |
| })); | |
| const context = $objc("NSMutableDictionary").$dictionary(); | |
| context.$setObject_forKey(modifier, "downloadRequestModifier"); | |
| const progressBlock = $block("void, NSInteger, NSInteger, NSURL *", (received, expected, target) => { | |
| console.log(`${received} / ${expected}`); | |
| }); | |
| const completionBlock = $block("void, UIImage *, NSData *, NSError *, NSInteger, BOOL, NSURL *", (image, data, error, type, finished, url) => { | |
| if (image) { | |
| $share.sheet(image.jsValue()); | |
| } else if (data) { | |
| $share.sheet(data.jsValue()); | |
| } else { | |
| console.log(error); | |
| } | |
| }); | |
| manager.$loadImageWithURL_options_context_progress_completed( | |
| url, | |
| options, | |
| context, | |
| progressBlock, | |
| completionBlock | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment