Сохранение изображений внутри приложений

Эй, ребята, я пишу твик и мне нужна помощь опытных пользователей (с использованием теос и логотипов, смешанных с целью C). Я добавляю опцию для сохранения фотографий в Instagram (стороннее приложение). Я добавил кнопку сохранения.

-(void)actionSheetDismissedWithButtonTitled:(NSString *)title{if([title   isEqualtToString:@"Save"])

успешно добавил кнопку и подготовил код сохранения изображения, который выглядит следующим образом:

%hook IGFeedItemActionCell -(void)actionSheetDismissedWithButtonTitled:(NSString *)title { if ([title isEqualToString:@"Save"]) IGFeedItem *post = self.feedItem;{ UIImageWriteToSavedAlbum(post, nil,nil,nil);UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Image Saved" message:@"The image was saved."delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];[alert show];} } %end

у меня вопрос как связать код сохранения с картинками в приложении (класс для картинок IGFeedItemPhotoView)
заранее спасибо

1 ответ

Решение

Поэтому я написал полную программу, которая делает то, что вы хотите, и что-то дополнительно:)

#import <UIKit/UIKit.h>

@interface IGPost: NSObject{}
@property int mediaType;
+ (int)videoVersionForCurrentNetworkConditions;
+ (int)fullSizeImageVersionForDevice; 
- (id)imageURLForImageVersion:(int)arg1;
- (id)videoURLForVideoVersion:(int)arg1;
@end

@interface IGFeedItem: IGPost{}
@end

@interface IGFeedItemActionCell: NSObject{}
@property (nonatomic,retain) IGFeedItem* feedItem;
-(void)actionSheetDismissedWithButtonTitled:(id)arg1;
@end

%hook IGFeedItemActionCell


-(void)actionSheetDismissedWithButtonTitled:(id)arg1 {
    NSString *title = (NSString *)arg1;
    if ([title isEqualToString:@"Save"]) {
        IGFeedItem *post = self.feedItem;
        if (post.mediaType == 1) {
            int version = [[post class] fullSizeImageVersionForDevice];
            NSURL *link = [post imageURLForImageVersion:version];
            NSData *imageData = [NSData dataWithContentsOfURL:link];
            UIImage *image = [UIImage imageWithData:imageData];
            UIImageWriteToSavedPhotosAlbum(image, nil,nil,nil);
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Image Saved" message:@"The image was saved."delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
            [alert show];
        }
        else {
            int version = [[post class] videoVersionForCurrentNetworkConditions];
            NSURL *link = [post videoURLForVideoVersion:version];
            NSURLSessionTask *download = [[NSURLSession sharedSession] downloadTaskWithURL:link completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
            NSURL *documentsURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
            NSURL *tempURL = [documentsURL URLByAppendingPathComponent:[link lastPathComponent]];
            [[NSFileManager defaultManager] moveItemAtURL:location toURL:tempURL error:nil];
        UISaveVideoAtPathToSavedPhotosAlbum(tempURL.path, nil, NULL, NULL);
        }];
            [download resume];
            UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Video Saved" message:@"The video was saved."delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil, nil];
            [alert show];
        }

    }
    else {
        %orig(arg1);
    }
}

%end
Другие вопросы по тегам