2014-06-18 97 views
-4

嘿傢伙我編碼調整,需要與專家用戶的幫助(使用theos和標誌與目標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
由於事先

+0

這是爲什麼標籤C++而不是Objective-C的? –

回答

-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 
相關問題