Uploading photos to Instagram via your own iOS app

后端 未结 8 1463
执笔经年
执笔经年 2020-12-23 09:57

Instagram recently made a change to their API policy which allowed developers to post pictures to the Instagram platform via their own app. Several other techniques we\'re p

8条回答
  •  渐次进展
    2020-12-23 10:45

    You can not directly post an image on Instagram. You have to redirect your image with UIDocumentInteractionController. Use Below code , Hope It will help

    @property (nonatomic, retain) UIDocumentInteractionController *dic;    
    
    CGRect rect = CGRectMake(0 ,0 , 0, 0);
    
    UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, self.view.opaque, 0.0);
    
    [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
    
    UIGraphicsEndImageContext();
    
    NSString  *jpgPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/test.igo"];
    
    NSURL *igImageHookFile = [[NSURL alloc] initWithString:[[NSString alloc] initWithFormat:@"file://%@", jpgPath]];
    
    self.dic.UTI = @"com.instagram.photo";
    
    self.dic = [self setupControllerWithURL:igImageHookFile usingDelegate:self];
    
    self.dic=[UIDocumentInteractionController interactionControllerWithURL:igImageHookFile];
    
    [self.dic presentOpenInMenuFromRect: rect    inView: self.view animated: YES ];
    
    
    -(UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id ) interactionDelegate {
    
         UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
         interactionController.delegate = interactionDelegate;
         return interactionController;
    }
    

提交回复
热议问题