WhatsApp图像共享iOS

WhatsApp图像共享iOS,ios,iphone,objective-c,whatsapp,Ios,Iphone,Objective C,Whatsapp,我正在开发一个iOS应用程序,其中我必须从我的应用程序中共享WhatsApp上的图像。我找到了这段代码,但它只处理使用documentationInteractionController可以实现的文本共享。 最近,我使用下面的代码将我们的应用程序中的图像共享到whatsApp、Line、微信,但当你点击whatsApp图标时,你就是应用程序中的导航whatsApp应用程序,你必须手动返回你的应用程序。图像共享后不会再次重定向 在.h文件中:- @interface ViewController

我正在开发一个iOS应用程序,其中我必须从我的应用程序中共享WhatsApp上的图像。我找到了这段代码,但它只处理使用
documentationInteractionController可以实现的文本共享。
最近,我使用下面的代码将我们的应用程序中的图像共享到whatsApp、Line、微信,但当你点击whatsApp图标时,你就是应用程序中的导航
whatsApp
应用程序,你必须手动返回你的应用程序。图像共享后不会再次重定向

在.h文件中:-

@interface ViewController : UIViewController<UIDocumentInteractionControllerDelegate>
{
}

@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;
@界面ViewController:UIViewController
{
}
@属性(非原子,保留)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;

}
-(iAction)点击:(ui按钮*)发送者{
NSArray*Path=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,是);
NSString*documentsDirectory=[paths objectAtIndex:0];
NSString*getImagePath=[documentsDirectory stringByAppendingPathComponent:@“savedImage.png”];//这里我从文档目录中获取图像路径,并将其转换为URL,然后使用下面的命令
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 PresentOpenMinumeFromRect:CGRectZero-inView:self.view-animated:YES];
}
-(UIDocumentInteractionController*)setupControllerWithURL:(NSURL*)文件URL
usingDelegate:(id)interactionDelegate{
self.documentationInteractionController=
[UIDocumentInteractionController interactionControllerWithURL:fileURL];
self.documentationInteractionController.delegate=交互委托;
返回self.documentationInteractionController;
}

在这段代码中,我们在哪里设置UIDocumentInteractionController的UTI。因为一旦这两行self.documentationInteractionController.UTI=@“net.whatsapp.image”;self.documentationInteractionController=[self-setupControllerWithURL:imageFileURL usingDelegate:self];覆盖它首先使用按钮单击测试此代码even@IronMan:
self.documentationInteractionController.UTI=@“net.whatsapp.image”通过此设置,您可以设置UTI!没有?事实上,我在我的项目中使用了上面的代码,并且我对它进行了测试,我能够共享图像。这是工作代码,我不明白您在哪里找到的。可以通过UIActivityViewControllerRefer共享此链接: