在我的应用程序中,我需要通过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];
}
但是问题在于,发送消息后,它不会自动返回我的应用程序。用户需要手动返回到应用程序。那么如何使它返回我的应用程序?可能吗?
最佳答案
这是不可能的。唯一可行的理论方法是发送要由whatsapp在其完成处理程序中打开的应用程序的URI。但是,whatsapp方案不支持此类功能,因此无法在发送消息后强制其打开您的应用程序。
关于ios - 如何以编程方式打开WhatsApp,然后返回我的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28606016/