如何在whatsapp上通过我的应用程序邀请用户并在IOS上共享内容?

如何在whatsapp上通过我的应用程序邀请用户并在IOS上共享内容?,ios,xcode6,share,whatsapp,invite,Ios,Xcode6,Share,Whatsapp,Invite,我已经尝试过这个代码,但它只显示whatsapp图标,但不发送内容。请建议我的错误 - (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate { self.documentationInteractionContr

我已经尝试过这个代码,但它只显示whatsapp图标,但不发送内容。请建议我的错误

- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL usingDelegate: (id <UIDocumentInteractionControllerDelegate>) interactionDelegate {

    self.documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL: fileURL];
    self.documentationInteractionController.delegate = interactionDelegate;
    return self.documentationInteractionController;
}


-(void)btnClick{
    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*)设置控制器,其URL:(NSURL*)文件URL使用委托:(id)interactionDelegate{
self.documentationInteractionController=[UIDocumentInteractionController interactionControllerWithURL:fileURL];
self.documentationInteractionController.delegate=交互委托;
返回self.documentationInteractionController;
}
-(无效)b单击{
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];
}

在whatsapp上发送短信:

        NSURL *whatsappURL = [NSURL URLWithString:@"whatsapp://send?text=Test%20message%20whatsapp!"];

        if ([[UIApplication sharedApplication] canOpenURL:whatsappURL]) {
            [[UIApplication sharedApplication] openURL: whatsappURL];
        } else {
            UIAlertView *warningAlert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Your device doesn't support Whatsapp!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [warningAlert show];
        }
编辑: 和图像:

    if ([[UIApplication sharedApplication] canOpenURL: [NSURL      URLWithString:@"whatsapp://app"]]){

UIImage     * iconImage = [UIImage imageNamed:@"YOUR IMAGE"];
NSString    * savePath  = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];

_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
_documentInteractionController.UTI = @"net.whatsapp.image";
_documentInteractionController.delegate = self;

[_documentInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];


    } else {
        UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
    }
看看whatsapp: 而这一回应:
如果您想要一个与Whatsapp集成的共享套件:

感谢您的快速回复,我感谢您的支持。上面的代码可以很好地用于共享文本,但我需要共享url,所以我需要将NSString转换为某种html类型的url。ShareKit缺少一些文件,它会导致很多错误。您可以共享消息文本中的链接:NSURL*whatsappURL=[NSURL URLWithString:@”whatsapp://send?text=Download%20my%20application%20here:%20http://itunes.apple.com/app/id000000191"];