2013-05-14 2 views
2

에 이미지 업로드 I는 다음과 인스 타 그램에 이미지를 업로드 할 수있는 코드를 작성했습니다 :아이폰 : 인스 타 그램

CGRect rect = CGRectMake(20 ,20 , 200, 200); 
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0); 
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIGraphicsEndImageContext(); 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 
    NSString *jpgPath = [documentsDirectory stringByAppendingPathComponent:@"after2sm.ig"]; 

    NSString *fileURL = [NSString stringWithFormat:@"file://%@",jpgPath]; 
    NSURL *igImageHookFile = [NSURL fileURLWithPath:fileURL]; 

    self.dic.UTI = @"com.instagram.photo"; 

    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self]; 
    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 

    [NSDictionary dictionaryWithObject:@"My Caption" forKey:@"InstagramCaption"]; 
    [self.dic presentOpenInMenuFromRect:rect inView:self.view animated:YES]; 

을 그러나 "인스 타 그램"옵션으로 actionsheet를 엽니 다하지만 난 그 아무것도 클릭 할 때 발생합니다. 당신이 날

+0

답장을 보내 주셔서 감사합니다. – user1954352

답변

6

이 시도 도와주세요 .can,이 코드에서 는

- (IBAction)InstagramButtonClick 
    { 

     CGRect rect = CGRectMake(0.0, 0.0, 612, 612); 
     UIGraphicsBeginImageContext(rect.size); 
     [imgUpload drawInRect:rect]; 

     UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 

     UIGraphicsEndImageContext(); 
     NSString *savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"]; 
     [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=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile]; 
      self.dic.annotation = [NSDictionary dictionaryWithObject:@"your message" forKey:@"InstagramCaption"]; 
     [self.dic presentOpenInMenuFromRect: CGRectZero inView: self.view animated: YES ]; 

    } 

// 대리자를 추가 imgUpload 객체에 이미지를 설정 UIDocumentInteractionControllerDelegate d 다음은 대표 메서드입니다

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { 
     UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 
     interactionController.delegate = interactionDelegate; 
     return interactionController; 

} 
+0

에 감사드립니다. 하지만 당신의 코드로 같은 결과가 나옵니다. – user1954352

+0

이미지 크기가 620 * 620 –

+0

이상이어야하며 intstagram 앱이 기기에 설치되어 있어야합니다. 필요합니다 –