1

In my app I need to send links via WhatsApp. So this is how I do that:

 NSString* link = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
                                                                                   (CFStringRef)resource.shareURL.absoluteString,
                                                                                   NULL,
                                                                                   CFSTR("!*'();:@&=+$,/?%#[]"),
                                                                                   kCFStringEncodingUTF8));

            NSString * urlWhats = [NSString stringWithFormat:@"whatsapp://send?text=%@", link];
            NSURL * whatsappURL = [NSURL URLWithString:urlWhats];

            if ([[UIApplication sharedApplication] canOpenURL: whatsappURL]) {
                [[UIApplication sharedApplication] openURL: whatsappURL];
            } else {
                UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Unknown error"
                                                                 message:@"Can't open Whatsapp"
                                                                delegate:nil
                                                       cancelButtonTitle:@"OK"
                                                       otherButtonTitles:nil];
                [alert show];
            }

But the problem is that it doesn't return automatically to my app after the message is sent. User needs to get back to the app manually. So how do I make it return to my app? Is it even possible?

Andrey Chernukha
  • 21,488
  • 17
  • 97
  • 161
  • This could only work if whatsapp supported the x-callback-url scheme that returns to your app after you're done in theirs. – nanothread Feb 19 '15 at 13:29

1 Answers1

4

It's not possible. The only theoretic way for this to work would be to send URI for your app to be opened by whatsapp in their completion handler. However, whatsapp scheme doesn't support such things so there is no way to force it to open your app after it has sent the message.

Sulthan
  • 128,090
  • 22
  • 218
  • 270