我想在集合视图单元格中长按时共享MP3文件。我写了下面的代码但它什么也没有返回。我的意思是当我向自己发送电子邮件时。它不包含MP3文件,而且我也看不到WhatsApp部分。
let r = NSURL(fileURLWithPath: temp_url!)
//var activityItems: [Any] = [temp_url!]
let activityViewController = UIActivityViewController(activityItems: [r], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
let excludeActivities = [UIActivityType.airDrop, UIActivityType.print, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.addToReadingList, UIActivityType.postToFlickr, UIActivityType.postToVimeo, UIActivityType.postToFacebook, UIActivityType.message, UIActivityType.postToWeibo]
activityViewController.excludedActivityTypes = excludeActivities
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
// exclude some activity types from the list (optional)
activityViewController.excludedActivityTypes = [ UIActivityType.airDrop, UIActivityType.postToFacebook ]
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
答案 0 :(得分:-1)
我用以下代码解决了这个问题;
if(temp_url != nil){
let activityViewController = UIActivityViewController(activityItems: [temp_url!], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view // so that iPads won't crash
// exclude some activity types from the list (optional)
let excludeActivities = [UIActivityType.airDrop, UIActivityType.print, UIActivityType.assignToContact, UIActivityType.saveToCameraRoll, UIActivityType.addToReadingList, UIActivityType.postToFlickr, UIActivityType.postToVimeo, UIActivityType.postToFacebook, UIActivityType.message, UIActivityType.postToWeibo]
activityViewController.excludedActivityTypes = excludeActivities
// present the view controller
self.present(activityViewController, animated: true, completion: nil)
}