Интеграция Instagram в iPhone - PullRequest
       3

Интеграция Instagram в iPhone

0 голосов
/ 01 марта 2012

Я пытаюсь опубликовать фотографию в Instagram через мое приложение. Я использую UIDocumentInteractionController в соответствии с инструкциями INstagram

в моем .h файле

UIDocumentInteractionController *documentInteractionController;

в моем .m файле

NSString *fileToOpen = [[NSBundle mainBundle] pathForResource:@"IMG_0192"  ofType:@"jpg"];
fileToOpen = [fileToOpen substringToIndex:[fileToOpen length] - 3];
 fileToOpen=[NSString stringWithFormat:@"%@ig",fileToOpen];
NSURL *instagramURL = [NSURL URLWithString:@"instagram://app"];
NSLog(@"%@",fileToOpen);
if ([[UIApplication sharedApplication] canOpenURL:instagramURL]) {
    //imageToUpload is a file path with .ig file extension
    /*UIAlertView *alert = [[UIAlertView alloc] 
                          initWithTitle:@"" 
                          message:@"Can open app!" 
                          delegate:self  
                          cancelButtonTitle:@"OK" 
                          otherButtonTitles:nil];
    [alert show];
    */



    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
    self.documentInteractionController.UTI = @"com.instagram.photo";
    self.documentInteractionController.annotation = [NSDictionary dictionaryWithObject:@"Its a testing" forKey:@"InstagramCaption"];

что-то упустил.? Не работает.

1 Ответ

1 голос
/ 22 марта 2013

Я думаю, что ваша фотография или URL файла неверны.Я успешно сделал это с помощью следующего фрагмента кода:

в вашем файле .h:

@property (nonatomic, retain) UIDocumentInteractionController *docDic;

и добавьте в ваш следующий делегат:

UIDocumentInteractionControllerDelegate

.m файл:

  1. синтезировать объект docDic

  2. Написать следующий метод:

    -(UIDocumentInteractionController *)setupControllerWithURL:(NSURL*)fileURL usingDelegate:(id<UIDocumentInteractionControllerDelegate>)interactionDelegate{
        UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
        interactionController.delegate = interactionDelegate;
        return interactionController;
    }
    
  3. Затем добавьте следующий фрагмент кода в функцию shareToInstagram:

    NSString * fileToOpen = [[NSBundle mainBundle] pathForResource: @ "IMG_0192" ofType: @ "jpg"];

    fileToOpen =[fileToOpen substringToIndex: [длина fileToOpen] - 3];

    fileToOpen = [NSString stringWithFormat: @ "% @. ig", fileToOpen];

    NSURL * instagramURL = [[NSURL alloc]initWithString: [[NSString alloc] initWithFormat: @ "file: //% @", fileToOpen]];

    if ([[UIApplication sharedApplication] canOpenURL: instagramURL]) {

    self.documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileToOpen]];
    

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

    [self.dic presentOpenInMenuFromRect: CGRectZero inView: self.viанимация: ДА];}

Надеюсь, это поможет вам.Удачи.: -)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...