ios - 将视频分享到什么应用程序而不显示 ActionSheet
<p><p>我需要将视频从我的应用程序分享到 WhatsApp。
我目前可以通过使用 <code>UIActivityViewController</code> 来做到这一点,但用户体验不好。</p>
<p>(用户按下“发送到 WhatsApp”按钮,然后必须在 <code>UIActivityViewController</code> 显示的操作表中选择 WhatsApp。</p>
<p>我知道可以打开 WhatsApp 应用程序并分享视频。
例如,应用程序 <code>TuneMoji</code> 做得很好:</p>
<ul>
<li>用户按下“发送到 WhatsApp”</li>
<li>WhatsApp 应用程序打开,询问目标用户。</li>
</ul>
<p>我也想做同样的事情。</p>
<p>请不要告诉我看<a href="https://www.whatsapp.com/faq/en/iphone/23559013" rel="noreferrer noopener nofollow">https://www.whatsapp.com/faq/en/iphone/23559013</a> ,或使用 <code>UIDocumentInteractionController</code> :我想避免向用户展示 ActionSheet。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在按钮操作上试试这个:</p>
<pre><code>func sendVideo(videoName: String, senderView: UIView) {
if UIApplication.sharedApplication().canOpenURL(NSURL(string: "whatsapp://app")!) {
let savePath: String = NSBundle.mainBundle().pathForResource(videoName, ofType: "mov")!
let documentInteractionController = UIDocumentInteractionController(URL: NSURL.fileURLWithPath(savePath))
documentInteractionController.UTI = "net.whatsapp.movie"
documentInteractionController.delegate = self
documentInteractionController.presentOpenInMenuFromRect(CGRectMake(0, 0, 0, 0), inView: senderView, animated: true)
}
else {
let alertController = UIAlertController(title: "Error occured", message: "WhatsApp is not installed on your device.", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alertController.addAction(defaultAction)
presentViewController(alertController, animated: true, completion: nil)
}
}
</code></pre>
<p>有关更多信息,您可以查看引用:<a href="https://www.whatsapp.com/faq/en/iphone/23559013" rel="noreferrer noopener nofollow">https://www.whatsapp.com/faq/en/iphone/23559013</a> </p>
<blockquote>
<p>Be sure to include WhatsApp URL scheme in your application's
Info.plist under LSApplicationQueriesSchemes key if you want to query
presence of WhatsApp on user's iPhone using 'canOpenURL'</p>
</blockquote></p>
<p style="font-size: 20px;">关于ios - 将视频分享到什么应用程序而不显示 ActionSheet,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/36472743/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/36472743/
</a>
</p>
页:
[1]