ios - 无需菜单 ios 即可自动分享到 whatsapp

标签 ios audio share whatsapp

我有一个声音想在 Whatsapp 上分享,使用 UIDocumentInteractionController 它工作得很好,但我不想促使用户选择 Whatsapp,我希望它被立即选中。这可能吗?

对于我想要的文本共享,它会立即使用深层链接打开 Whatsapp

whatsapp://send?text=test

我不希望在共享声音时显示此菜单: menu

最佳答案

对于文本:

NSString * msg = @"Your Text";
NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@",msg];

NSURL * whatsappURL = [NSURL URLWithString:[urlWhats stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
    [[UIApplication sharedApplication] openURL: whatsappURL];

}

else{

UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"WhatsApp not installed." message:@"Your device has no WhatsApp installed." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];

}

对于图像:

.h 文件:

<UIDocumentInteractionControllerDelegate>

@property (retain) UIDocumentInteractionController * documentInteractionController;

.m 文件:

    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];
 }

关于ios - 无需菜单 ios 即可自动分享到 whatsapp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31914194/

相关文章:

ios - 将通知中心设置为单次滑动还是两次滑动

cocoa-touch - Objective C - 通过 MFMailComposeViewController 的附件未显示

java - 使用 (Java) AudioInputStream 打开 wav 文件时出现问题

java - 如何在多个 Web 应用程序之间共享公共(public)资源?

ios - 低功耗模式下的 UNNotificationAction 处理程序

iphone - Objective-C 在 iPhone 上测试应用程序,更新数据,数据没有改变

objective-c - 如何自动推送

c - 为什么我的输入通过管道发送到进程时会延迟?

javascript - Facebook 与自定义和动态数据共享问题

android - 仅针对文件的 Intent 过滤器