嘿伙计我正在编码调整并需要专家用户的帮助(使用与目标C混合的theos和徽标)我添加了一个选项来保存Instagram中的照片(第三方应用程序)我添加了一个保存按钮< / p>
-(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
)
提前谢谢
答案 0 :(得分:-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