ios - 如何以编程方式打开WhatsApp,然后返回我的应用程序?

标签 ios objective-c cocoa-touch whatsapp

在我的应用程序中,我需要通过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/

相关文章:

iOS UITextView 或 UILabel 带有可点击的 Action 链接

ios - 如何从 Xcassets 获取 iOS 版本特定的 Assets

ios - 带有 : ERROR: Cannot find schemes 的 Travis-CI

iphone - iPhone 只能使用 SQLite 数据库吗?

ios - 阻止 iOS 将单词添加到 UITextField 中输入的字典中?

ios - 如何检测我的应用程序的首次启动并运行指定的 View Controller ?

ios - 设置UILabel中的文本垂直和水平居中,而不改变框架

IOS Storyboard : Load Multiple Subviews for given position

ios - 从静态库初始化对象时,在构建过程中发生编译错误

ios - 难以在 Xcode 中归档静态库(未找到)