1

I have a sound which i want to share on Whatsapp, using the UIDocumentInteractionController it is working perfectly, but i don't want to promote the user to choose Whatsapp, i want it to be picked immediately. Is that possible ?

For the text share it works as i want, it immediately open Whatsapp using the deep linking

whatsapp://send?text=test

I dont want this menu to be shown when sharing sound: menu

Community
  • 1
  • 1
user5132182
  • 31
  • 1
  • 3

1 Answers1

1

For Text :

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

}

For Image :

.h file :

<UIDocumentInteractionControllerDelegate>

@property (retain) UIDocumentInteractionController * documentInteractionController;

.m file :

    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];
 }
iPhone developer.
  • 2,122
  • 1
  • 16
  • 17