I have an iOS App similar to Photos App from Apple, which also has a ‘Share’ button for sharing photo, which worked well before. The code is as follows (for simplicity, I changed the sharing content to a string):
@objc func shareButtonTapped()
{
let vc = UIActivityViewController(activityItems: ["www.apple.com"], applicationActivities: nil);
if let pop = vc.popoverPresentationController
{
pop.sourceView = someView;
pop.sourceRect = shareButton.frame;
}
self.present(vc, animated: true, completion: nil);
}
But when my iPhone was upgraded to iOS 15, the UIActivityViewController that is showed up was invisible. I attach an operation video: enter link description here Observe carefully, in fact, UIActivityViewController has a pop-up, but it has become almost transparent.
Then, I added a statement to deliberately set the background color of its view:
@objc func shareButtonTapped()
{
let vc = UIActivityViewController(activityItems: ["www.apple.com"], applicationActivities: nil);
vc.view.backgroundColor = UIColor.systemBackground;
if let pop = vc.popoverPresentationController
{
pop.sourceView = someView;
pop.sourceRect = shareButton.frame;
}
self.present(vc, animated: true, completion: nil);
}
The operation video is as follows: enter link description here
This code is very simple and very standard. I don't know why this happens? Hope someone can help. Thanks in advance!
In fact, I define the shareButton within a class derived from UICollectionViewCell:
class AssetPreviewCell: UICollectionViewCell, UIScrollViewDelegate, PHLiveViewDelegate, UINavigationControllerDelegate
{
//....
}
And the complete code is:
@objc func shareButtonTapped()
{
guard let svc = self.findViewController() else { return }
let vc = UIActivityViewController(activityItems: ["www.apple.com"], applicationActivities: nil);
if let pop = vc.popoverPresentationController
{
pop.sourceView = someView;
pop.sourceRect = shareButton.frame;
}
svc.present(vc, animated: true, completion: nil);
}
The func findViewController() is the method from enter link description here
Edit:
And I have an 'Albums' button next to the 'Share' button. When the 'Albums' button is tapped, I present another view controller for add current photo to albums or remove current photo from albums according user select or deselect. This view controller is presented quiet normally. The operation video is on enter link description here . So I think the problem is just from UIActivityViewController or something else.
I find the answer. The problem is caused because I overrided the viewDidLoad function of UIActivityViewController for some reason:
override open func viewDidLoad()
{
super.viewDidLoad();
a_var += 1;
}
This cause problem on iOS15 while works well on iOS14 or iOS13.
Now I override the viewDidAppear(_) instead and the problem dissappears:
override open func viewDidAppear(_ animated: Bool)
{
super.viewDidAppear(animated);
a_var += 1;
}
ps: @mczmma is another account of mine. This account is restricted to ask question. I don't know the reason.