在WhatsApp上共享多个媒体文件(音频/视频/图像)

时间:2014-12-05 06:10:35

标签: ios iphone ipad xcode6

我想知道如何在什么应用上共享多个媒体文件。 如果有相同的问题,请指导我。 这是我用于Text的代码,

- (void)WhatsAppClicked
{
    NSString *textwithTitle=[NSString stringWithFormat:@"-%@\n\n%@",LS_detailTitleLabel.text,LS_detailTextView.text];
    NSString *textURL=[NSString stringWithFormat:@"whatsapp://send?text=%@",textwithTitle];//make string
    textURL=[textURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];//now make string look like URL
    NSURL *whatsappURL = [NSURL URLWithString:textURL];//now pass it into URL
    if ([[UIApplication sharedApplication] canOpenURL: whatsappURL])
    {
        [[UIApplication sharedApplication] openURL: whatsappURL];
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"WhatsApp Error...!" message:@"WhatsApp Might not installed on your phone.Install it and try again" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
    }
}

此代码非常适合发送文本。 在此先感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用此代码分享您的图片

此处image_share是您要分享的图片

-(void)whatsappShare
{
if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]])
{
    UIImage *iconImage = image_share;
    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:@"Please Install WhatsApp Application to share" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue",nil];
    [alert show];
}
}