I am displaying a UIActivityViewController in my app, but the first time I do this, it takes ages to pop, like 5+ seconds. The next times I don't have this issue however.
Here is how I call it:
DispatchQueue.main.async {
let avc = UIActivityViewController(activityItems: [url], applicationActivities: nil)
avc.excludedActivityTypes = [.airDrop]
self.present(avc, animated: true, completion: nil)
}
I also tried adding this trick in AppDelegate, but with no luck:
let avc = UIActivityViewController(activityItems: ["start"], applicationActivities: nil)
avc.becomeFirstResponder()
avc.resignFirstResponder()
Thank you for your help
Related
I am excluding .postToWeibo but still I can see Weibo app in the options of UIActivityViewController. My code is
var activityViewController = UIActivityViewController(activityItems: [documentId+".pdf", pDfdata], applicationActivities: nil)
activityViewController.excludedActivityTypes = [.postToTwitter, .postToFacebook, .postToFlickr, .postToTencentWeibo, .postToVimeo, .postToWeibo]
present(activityViewController, animated: true)'''
Can you please let me know what is the reason for this?
I share an invite through UIActivityViewController by passing the text. I am able to achieve it. But I have display issue as shown in the image below. A greyed box displayed over the text at the top. Below is my code
let objectToShare = inviteReferrals.inviteData
let vc = UIActivityViewController(activityItems: [objectToShare], applicationActivities: [])
present(vc, animated: true)
Can any one help me, why this box comes and how to avoid it.
ActivityViewControllerDisplay
let activityViewController = UIActivityViewController(activityItems: [objectToShare], applicationActivities: nil)
activityViewController.popoverPresentationController?.sourceView = self.view
self.present(activityViewController, animated: true, completion: nil)
Here is my code
let myURL = URL(string: "http://www.dwz.cn/BabySmarter")
let shareActivity = UIActivityViewController(activityItems: [myURL!, "我的宝宝比\(String(describing: Int(finalScore!)))% 的宝宝更发展!你的呢?"], applicationActivities: nil)
shareActivity.popoverPresentationController?.sourceView = self.view
self.present(shareActivity, animated: true, completion: nil)
Here is the result:
This has to be a glitch. Or am I completely wrong here?
May be problem with URL , you can pass url as string.
let shareActivity = UIActivityViewController(activityItems: ["http://www.dwz.cn/BabySmarter 我的宝宝比\(String(describing: Int(finalScore!)))% 的宝宝更发展!你的呢?"], applicationActivities: nil)
shareActivity.popoverPresentationController?.sourceView = self.view
self.present(shareActivity, animated: true, completion: nil)
I am having issues w/rendering UIActivityViewController.
Using the following code:
let objectsToShare: NSArray = ["test", "http://www.test.com"];
let activityVC: UIActivityViewController = UIActivityViewController(activityItems: objectsToShare as [AnyObject], applicationActivities: nil)
self.presentViewController(activityVC, animated: true, completion: nil)
renders the following ActivityViewController:
Anyone has faced similar issue and knows a workaround?
Also, sometimes the rendering issue becomes even worse:
I have a UIActivityViewController for a share button. For iPhone I have it as a regular UIActivityViewController and for iPad its in a PopOverViewController. This is the code I have for it
let textToShare = "Check out this website!"
if let myWebsite = NSURL(string: "http://www.apple.com/") {
let objectsToShare = [textToShare, myWebsite]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
if let popUpVC = activityVC.popoverPresentationController {
popUpVC.permittedArrowDirections = .Any
popUpVC.sourceRect = share.frame
}
self.view?.window?.rootViewController?.presentViewController(activityVC, animated: true, completion: nil)
}
When I press the share button on a iPad it just crashes with a (lldb). But when I have it present from a view it works but isn't in the right position. This is the code I am using for the present from a view.
popUpVC.sourceView = self.view
Try this, you have to check if the device you are currently running on responds to popoverPresentationController because popoverPresentationController is new to iOS 8 and will crash on iOS 7. It'll also be nil on iPhone because it's only in a UIPopover on iPad.
let activityViewController = UIActivityViewController(activityItems: [myText, myUrl], applicationActivities: nil)
if activityViewController.respondsToSelector("popoverPresentationController") {
// iOS8+
view.presentViewController(activityViewController, animated: true, completion: nil)
activityViewController.popoverPresentationController?.sourceView = view
} else {
view.presentViewController(activityViewController, animated: true, completion: nil)
}