Swift: UIActivityViewController - ios

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)

Related

Weibo is not getting excluded in UIActivityViewController

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?

UIActivityViewController takes a lot of time when first appears

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

UIActivityController Not Showing full on screen

i am Presenting UIActivityController But it Showing Half on screen.
let textToShare = "This is awesome! Check out this website about it!"
if let myWebsite = NSURL(string:urlShare) {
let objectsToShare = [textToShare, myWebsite]
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//New Excluded Activities Code
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]
self.navigationController!.presentViewController(activityVC, animated: true, completion: nil)
Have you try to self.presentViewController on the current ViewController instead of on the self.navigationController.
I use to have this issue as my rootViewController is larger and therefore when presenting using the self.navigationController it get cut off.
Try adding inside a POP UPViewController
var popup = UIPopoverController(contentViewController: controller)
popup.presentPopoverFromRect(CGRectMake(self.view!.frame.size.width / 2, self.view!.frame.size.height / 4, 0, 0), inView: self.view!, permittedArrowDirections: .Any, animated: true)
here, controller is your activityVC

Issues with presenting UIActivityViewController

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:

UIActivityViewController in a PopOverViewController Crashing in Swift

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)
}

Resources