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

问题描述 投票:1回答:1

我想在Whatsapp上共享声音,使用UIDocumentInteractionController可以正常工作,但是我不想促使用户选择Whatsapp,我希望它可以立即被挑选出来。那可能吗 ?

对于文本共享,它可以按我的需要工作,它会立即使用深层链接打开Whatsapp

whatsapp://send?text=test

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

ios audio share whatsapp
1个回答
1
投票
对于文本:

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

© www.soinside.com 2019 - 2024. All rights reserved.