2014-02-25 62 views
0

我正在與Instagram分享照片,有些應用程序通過照片插入標記,我該怎麼做?如何爲Instagram分享插入標記與照片

enter image description here

- (void)instagramWithImage:(UIView*)view openInView:(UIViewController*)viewCont 

{ 

      UIView* captureView = view; 


     /* Capture the screen shoot at native resolution */ 
     UIGraphicsBeginImageContextWithOptions(captureView.bounds.size, NO, 0.0); 
     [captureView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
     UIImage * screenshot = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 


     /* Render the screen shot at custom resolution */ 
     CGRect cropRect = CGRectMake(0 ,0 ,1024 ,1024); 
     UIGraphicsBeginImageContextWithOptions(cropRect.size, NO, 1.0f); 
     [screenshot drawInRect:cropRect]; 
     UIImage * customScreenShot = UIGraphicsGetImageFromCurrentImageContext(); 
     UIGraphicsEndImageContext(); 


     NSURL *url; 
     docFile.delegate = self; 

     //Save image to directory 
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
     NSString *documentsDirectory = [paths objectAtIndex:0]; 
     NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"]; 


     UIImage *image = customScreenShot; 

     NSData *imageData = UIImagePNGRepresentation([image imageByApplyingSharpen3x3]); 
     [imageData writeToFile:savedImagePath atomically:NO]; 

     //load image 
     NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.jpg"]; 
     UIImage *tempImage = [UIImage imageWithContentsOfFile:getImagePath]; 

     //Hook it with Instagram 
     NSString *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/Image.ig"]; 
     [UIImageJPEGRepresentation(tempImage, 1.0) writeToFile:jpgPath atomically:YES]; 

     url = [[NSURL alloc] initFileURLWithPath:jpgPath]; 
     docFile = [UIDocumentInteractionController interactionControllerWithURL:url]; 
     [docFile setUTI:@"com.instagram.photo"]; 

    CGRect rect = viewCont.view.bounds; 
     [docFile presentOpenInMenuFromRect:rect inView:viewCont.view animated:YES]; 



} 
+0

什麼是你的代碼張貼在Instagram的? – Larme

+0

@Larme檢查我編輯的問題 –

回答

3

您可以使用UIDocumentInteractionController的註釋屬性來設置標題

documentInteractionController.annotation = @{@"InstagramCaption" : @"yourCustomTag" }; 

更多的相關信息:Instagram Documentation Source

相關問題