通过WhatsApp共享文件音频

时间:2015-01-10 14:24:15

标签: objective-c xcode ipa whatsapp

这是通过WhatsApp进行图像共享的代码。 但我无法理解如何修改它来发送音频文件。 如果有人知道我可以写修改?请。

- (IBAction)Share:(UIButton *)sender 
{
    if ([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"whatsapp://app"]]){
    UIImage * iconImage = [UIImage imageNamed:@"NAMEIMAGE.jpeg"];
    NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.wai"];

   [UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
   _documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
   _documentationInteractionController.UTI = @"net.whatsapp.image";    
   _documentationInteractionController.delegate = self;    

   [_documentationInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
} 
else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Errore" message:@"Sul tuo dispositivo non è installato WhatsApp." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
  }
}
- (UIDocumentInteractionController *) setupControllerWithURL: (NSURL*) fileURL
usingDelegate: (id ) interactionDelegate {
self.documentationInteractionController =    
[UIDocumentInteractionController interactionControllerWithURL: fileURL];
self.documentationInteractionController.delegate = interactionDelegate;

return self.documentationInteractionController;
}

1 个答案:

答案 0 :(得分:1)

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

    //UIImage * iconImage = [UIImage imageNamed:@"myphoto.jpg"];
    NSString * savePath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/whatsAppTmp.waa"];

    savePath = [[NSBundle mainBundle] pathForResource:@"myaudio" ofType:@"mp3"];

    //[UIImageJPEGRepresentation(iconImage, 1.0) writeToFile:savePath atomically:YES];
    _documentationInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:savePath]];
    _documentationInteractionController.UTI = @"net.whatsapp.audio";
    _documentationInteractionController.delegate = self;

    [_documentationInteractionController presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) inView:self.view animated: YES];
}
else {
    UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Errore" message:@"Sul tuo dispositivo non è installato WhatsApp." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
}