Skip to content

Instantly share code, notes, and snippets.

@Gandum2077
Created January 8, 2020 02:15
Show Gist options
  • Select an option

  • Save Gandum2077/e2a3e830d38e0ab2583e8a6225c900fd to your computer and use it in GitHub Desktop.

Select an option

Save Gandum2077/e2a3e830d38e0ab2583e8a6225c900fd to your computer and use it in GitHub Desktop.
Using SDWebImageManager in JSBox
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