Download GIFs with Antenna Browser for Reddit natively
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

80 lines
2.7KB

  1. #import <Photos/Photos.h>
  2. #import <AssetsLibrary/AssetsLibrary.h>
  3. #import "MBProgressHUD.h"
  4. @interface RCGIFViewController : UIViewController
  5. @property(assign, nonatomic) NSURL *mp4URL;
  6. @end
  7. #define SETUP_LONGPRESS_ONCONTROLLER UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPress:)]; longPress.minimumPressDuration = 1.5; [self.view addGestureRecognizer:longPress];
  8. %hook RCGIFViewController
  9. -(void)viewDidLoad
  10. {
  11. SETUP_LONGPRESS_ONCONTROLLER
  12. %orig;
  13. }
  14. %new
  15. -(void)handleLongPress:(UILongPressGestureRecognizer *)sender
  16. {
  17. UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  18. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  19. [sender setEnabled:YES];
  20. // Cancel button tappped.
  21. [self dismissViewControllerAnimated:YES completion:^{
  22. }];
  23. }]];
  24. [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save GIF" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
  25. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  26. hud.label.text = @"Downloading";
  27. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  28. NSLog(@"Downloading Started");
  29. NSURL *url = self.mp4URL;
  30. NSData *urlData = [NSData dataWithContentsOfURL:url];
  31. if ( urlData )
  32. {
  33. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  34. NSString *documentsDirectory = [paths objectAtIndex:0];
  35. NSString *filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"];
  36. dispatch_async(dispatch_get_main_queue(), ^{
  37. hud.label.text = @"Saving";
  38. [urlData writeToFile:filePath atomically:YES];
  39. NSLog(@"File Saved !");
  40. hud.label.text = @"Importing";
  41. [sender setEnabled:YES];
  42. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  43. NSString *documentsDirectory = [paths objectAtIndex:0];
  44. [[[ALAssetsLibrary alloc] init] writeVideoAtPathToSavedPhotosAlbum:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", documentsDirectory,@"tempVideo.mp4"]] completionBlock:^(NSURL *assetURL, NSError *error) {
  45. if(assetURL) {
  46. hud.label.text = @"DONE!";
  47. [hud hideAnimated:YES];
  48. } else {
  49. hud.label.text = @"ERROR. Try Again.";
  50. }
  51. }];
  52. });
  53. }
  54. });
  55. [self dismissViewControllerAnimated:YES completion:^{
  56. }];
  57. }]];
  58. // Present action sheet.
  59. [self presentViewController:actionSheet animated:YES completion:nil];
  60. }
  61. %end