2013-08-05 1 views
0

내 앱의 Instagram에서 이미지를 공유하고 싶습니다.하지만 문제는 동일한 이미지를 두 번 공유하면 이미지가 확대되고 이미지의 일부가 엉망이되어 공유하는 코드입니다.iOS에서 인스 타 그램을 공유하는 동안 이미지가 확대되는 이유는 무엇입니까?

-(void)shareImageToInstagram 

    { 
     myview.hidden = NO; 
     shareImage.image = [self ChangeViewToImage:myview]; 

     NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"]; 


      CGRect cropRect=CGRectMake(0,0,306,306); 
      NSString *savePath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"]; 
      CGImageRef imageRef = CGImageCreateWithImageInRect([shareImage.image CGImage], cropRect); 
      UIImage *img = [[UIImage alloc] initWithCGImage:imageRef]; 
      CGImageRelease(imageRef); 
      [UIImageJPEGRepresentation(img, 1.0) writeToFile:savePath atomically:YES]; 
      NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@",savePath]]; 
      self.dic.UTI = @"com.instagram.photo"; 
      self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
      self.dic.annotation = [NSDictionary dictionaryWithObject:kCheckOut forKey:@"InstagramCaption"]; 
     if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) 
     { 
      [self.dic presentOpenInMenuFromRect: CGRectZero inView: self.view animated: YES ]; 
      myview.hidden = YES; 
     } 
     else 
     { 
      ALERT_VIEW(@"Instagram not installed in this device!\nTo share image please install instagram."); 
      myview.hidden = YES; 
     } 
    } 

    - (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { 

     UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 
     interactionController.delegate = interactionDelegate; 
     myview.hidden = YES; 
     return interactionController; 
    } 

답변

1

항상 업데이트해야합니다. 다음 작업이 효과적입니다 (인터페이스에서 documentInteractionController를 선언 한 경우).

NSURL *instagramURL = [NSURL URLWithString:@"instagram://yourApp"]; 

if ([[UIApplication sharedApplication] canOpenURL:instagramURL]){ 
NSString *jpgPath=[NSHomeDirectory() stringByAppendingPathComponent:@"Documents/image.igo"]; 
     [UIImageJPEGRepresentation(yourImage, 1.0) writeToFile:jpgPath atomically:YES]; 

     NSURL *fileURL = [NSURL fileURLWithPath:jpgPath]; 
     documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:fileURL]; 
     documentInteractionController.UTI = @"com.instagram.exclusivegram"; 
     documentInteractionController.delegate = self; 

      documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Your App" forKey:@"InstagramCaption"]; 
     [documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 
관련 문제