From 1ab90e5776f7e9dd46c5509e0b485d09ce0186e3 Mon Sep 17 00:00:00 2001 From: Matthew Matter Date: Tue, 3 Jan 2017 10:35:28 -0500 Subject: [PATCH] Fix - Save Poll Images --- Tweak.xm | 123 +++++++++++++++++++++++++++---------------------------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/Tweak.xm b/Tweak.xm index 6bde924..bdee6ba 100644 --- a/Tweak.xm +++ b/Tweak.xm @@ -31,6 +31,10 @@ @property (assign, nonatomic) FLCollageSinglePhotoView* photoView; @end +@interface FLPollSinglePhotoViewController : UIViewController +@property (assign, nonatomic) FLImageView *photoView; +@end + %hook FLHubPhotoViewController -(void)viewDidLoad @@ -203,6 +207,62 @@ %end + +%hook FLPollSinglePhotoViewController + +-(void)viewDidLoad +{ + UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] + initWithTarget:self + action:@selector(handleLongPress:)]; + longPress.minimumPressDuration = 1.5; + [self.view addGestureRecognizer:longPress]; + %orig; +} + +%new +-(void)handleLongPress:(UILongPressGestureRecognizer *)sender +{ + UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + + [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { + + // Cancel button tappped. + [self dismissViewControllerAnimated:YES completion:^{ + }]; + }]]; + + [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { + + UIImage *snapshot = self.photoView.originalImage; + + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^ + { + PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot]; + changeRequest.creationDate = [NSDate date]; + } + completionHandler:^(BOOL success, NSError *error) + { + if (success) + { + NSLog(@"successfully saved"); + } + else + { + NSLog(@"error saving to photos: %@", error); + } + }]; + + [self dismissViewControllerAnimated:YES completion:^{ + }]; + }]]; + + // Present action sheet. + [self presentViewController:actionSheet animated:YES completion:nil]; +} + +%end + // IGNORE ABOVE. SAVES IMAGES //FLAVPlayerLayerView //FLHubVideoCollection @@ -286,65 +346,4 @@ [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil]; } -%end - -//%hook FLVideoContentHolderView - -//FL_doubleTapOnpost -/* -%hook FLAVPlayerLayerView --(id)init { - NSLog(@"IW HAVE BEEN INITIATEDDDDDDDDDDDDDD"); - UILongPressGestureRecognizer *longPress = [[[UILongPressGestureRecognizer alloc] - initWithTarget:self - action:@selector(handleLongPress:)] autorelease]; - longPress.minimumPressDuration = 2.0; - [self addGestureRecognizer:longPress]; - return %orig; - -} - - -%new --(void)handleLongPress:(UILongPressGestureRecognizer *)sender -{ - NSLog(@"Video URL: %@", self.videoView.videoURL); - UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; - - [actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { - - // Cancel button tappped. - [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{ - }]; - }]]; - - [actionSheet addAction:[UIAlertAction actionWithTitle:@"Save Image" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) { - - UIImage *snapshot = [self.photoView image]; - - [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^ - { - PHAssetChangeRequest *changeRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:snapshot]; - changeRequest.creationDate = [NSDate date]; - } - completionHandler:^(BOOL success, NSError *error) - { - if (success) - { - NSLog(@"successfully saved"); - } - else - { - NSLog(@"error saving to photos: %@", error); - } - }]; - - [[[UIApplication sharedApplication] keyWindow].rootViewController dismissViewControllerAnimated:YES completion:^{ - }]; - }]]; - - // Present action sheet. - [[[UIApplication sharedApplication] keyWindow].rootViewController presentViewController:actionSheet animated:YES completion:nil]; -}*/ - - +%end \ No newline at end of file