【问题标题】:Share an Image and Text on WhatsApp in IOS programmatically?以编程方式在 IOS 中的 WhatsApp 上共享图像和文本?
【发布时间】:2023-03-24 06:56:01
【问题描述】:

我将借助编码在 whatsapp 中添加图像和一些文本。如何执行它来解决我的问题?

【问题讨论】:

标签: ios objective-c iphone ipad xcode6


【解决方案1】:

您可以在 WhatsApp 上发布图片或文字。但是您不会同时发布两者,因为 whatsapp 不提供任何 API,您可以添加标题和发布带有文本的图像。

以下是将图片从 iPhone 应用程序以WhatsApp Documentation 发送到whatsapp 的示例:

在 ViewController.h 文件中:

@interface ViewController : UIViewController
{
}

@property(nonatomic,retain) UIDocumentInteractionController *documentationInteractionController;

在 ViewController.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 ) interactionDelegate {



    self.documentationInteractionController =

    [UIDocumentInteractionController interactionControllerWithURL: fileURL];

    self.documentationInteractionController.delegate = interactionDelegate;



    return self.documentationInteractionController;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-11
    • 2016-06-25
    • 2017-05-13
    • 2016-09-28
    • 1970-01-01
    • 2017-12-07
    • 2013-12-23
    • 1970-01-01
    相关资源
    最近更新 更多