2013-08-05 37 views
0

我想從我的應用程序Instagram上分享圖像它的工作相當好,但問題來了,當我第二次分享相同的圖像圖像變得放大和圖像的一些部分變得混亂在這裏是我的共享代碼。爲什麼在iOS上分享instagram時圖像變焦?

-(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];