2013-12-06 4 views
8

Я разрабатываю приложение iOS, в котором мне нужно обмениваться имиджем WhatsApp с моим приложением. Я нашел этот код, но он касается только обмена текстами. https://github.com/jberlana/JBWhatsAppActivityОбмен изображениями WhatsApp iOS

+0

Обратитесь к этой ссылке: http://www.whatsapp.com/faq/en/ iphone/23559013 –

ответ

8

Это можно использовать с помощью documentationInteractionController. Недавно я сделал это, используя следующий код для совместного использования изображения. Из нашего приложения в WhatsApp, Line, WeChat, но пока вы нажимаете на значок WhatsApp, вы используете навигационное приложение WhatsApp из своего приложения, и вы должны вернуть свое приложение вручную. Это не перенаправляется снова после ImageSharing.

в файле .h: -

@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate> 
{ 
} 

@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController; 

в .m файл

- (IBAction)bocClick:(UIButton *)sender { 


    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,  NSUserDomainMask, YES); 
    NSString *documentsDirectory = [paths objectAtIndex:0]; 

    NSString *getImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"]; //here i am fetched image path from document directory and convert it in to URL and use bellow 


    NSURL *imageFileURL =[NSURL fileURLWithPath:getImagePath]; 
    NSLog(@"imag %@",imageFileURL); 

    self.documentationInteractionController.delegate = self; 
    self.documentationInteractionController.UTI = @"net.whatsapp.image"; 
    self.documentationInteractionController = [self setupControllerWithURL:imageFileURL usingDelegate:self]; 
    [self.documentationInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; 


} 

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL 

               usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { 



    self.documentationInteractionController = 

    [UIDocumentInteractionController interactionControllerWithURL: fileURL]; 

    self.documentationInteractionController.delegate = interactionDelegate; 



    return self.documentationInteractionController; 

} 
+0

Где мы устанавливаем UTI для UIDocumentInteractionController в этом фрагменте кода. Потому что после этих двух строк self.documentationInteractionController.UTI = @ "net.whatsapp.image"; self.documentationInteractionController = [self setupControllerWithURL: imageFileURL usingDelegate: self]; перезапишите его – IronMan

+0

сначала проверьте этот код, используя кнопку click даже –

+1

@IronMan: 'self.documentationInteractionController.UTI = @" net.whatsapp.image ";' этим вы устанавливаете UTI! Нет? – Maulik

Смежные вопросы