在我的应用中,我需要通过WhatsApp发送链接。这就是我这样做的方式:
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];
}
但问题是在发送邮件后它不会自动返回我的应用程序。用户需要手动返回应用程序。那么如何让它返回我的应用程序?它甚至可能吗?
答案 0 :(得分:4)
这是不可能的。这个工作的唯一理论方法是发送你的应用程序的URI由whatsapp在他们的完成处理程序中打开。但是,whatsapp计划并不支持这样的事情,因此在发送消息后无法强制它打开你的应用程序。