Error "[ShareSheet] connection invalidated" error iOS13+ but not on iOS 11.4 - swift

I want to share a file using the Share Sheet and have written code that seems to work just fine. However I keep seeing these error messages in the log (using Xcode 11.3)
[ShareSheet] connection invalidated
I have two physical devices I'm testing on; an iPad running iOS 13.1.2 and an iPhone 6 running 11.4. I don't see these messages on the iPhone with the older iOS on it. Both cases the sharing seems to work just fine. Here's the code I'm using using text instead of a file:
let activityViewController = UIActivityViewController(activityItems: ["simple text for test"], applicationActivities: nil)
activityViewController.excludedActivityTypes = [.message, .airDrop]
activityViewController.popoverPresentationController?.barButtonItem = myBarButtonItem
self.present(activityViewController, animated: true, completion: nil)
The message shows up when the share sheet goes away (either because user completes an action, or they tap outside of it to cancel).
Is it safe to ignore these messages? It's just odd that they didn't show up in the older OS but do in the new one.
Edited on 20 Mar 2020: I validated that I was providing a valid source or barButtonItem. I've changed the code to match that where I'm using a UIBarButtonItem and I still see the ShareSheet connection invalidated error.

I got
[ShareSheet] connection invalidated
in the Xcode output log on iOS 13.x, and the share sheet was squished and did not have any buttons in it.
To fix it, assign your sourceView to something more specific than self.view
In my case, I had some UILabels near the top of my view, so I set my sourceView to one of those. For example, in my parent view controller, I had a UILabel named labelCustomerName so I used that:
activityViewController.popoverPresentationController?.sourceView = self.labelCustomerName

For me, it was solved when i added this code, based on Apple developer documentation.
activityViewController.isModalInPresentation = true
By the way, it seems like even if press the close button for the activity it still shows that message.

try this ...
let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fileURL = documentsPath.appendingPathComponent(filename)
let activityController = UIActivityViewController(activityItems: [fileURL], applicationActivities: nil)
present(activityController, animated: true, completion: nil)

Related

CALayer message while playing video (Xcode 12.5.1, Swift 5)

I'm using a stack view to hold various buttons to go to other view controllers, and one button plays a video. Whenever I press this, I get the following messages but the app works fine and the video plays properly:
CATransformLayer changing property masksToBounds in transform-only layer, will have no effect and changing property allowsGroupBlending in transform-only layer, will have no effect
Any idea? Video plays ok in simulator and on device. I'm using the view controller as player like below, Thanks!
guard let url = Bundle.main.path(forResource: "previewMovie", ofType: "m4v") else{return}
let player = AVPlayer(url: URL(fileURLWithPath: url))
let vc = AVPlayerViewController()
vc.player = player
present(vc, animated: true, completion: nil)
Can I ignore the message as it doesn't look like a warning or an error and considering the video plays and the app works fine? I have to resubmit the app. Thanks!
Yes, ignore it. Nothing's wrong with your code.

Show custom alert for camera and gallery permission swift 3

May be this is duplicate question but I actually didn't find exact solution. I have camera and photo gallery collection view on the same screen.see this UI
When I land to this screen, I get two alerts: one for camera access and other for photo access. Can anyone tell me how to get rid of these native alerts and implement the custom one alert for both the permissions.
You can get the image when picking is done with imagePickerController
First, implement the UIImagePickerControllerDelegate
Second, create an instance and set the delegate
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
Present the imagePicker with
present(imagePicker, animated: true, completion: nil)
And finally
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
imagePicker.dismiss(animated: true, completion: nil)
}
Now you have the image.
Whenever you will be add permission details inside your applications <Your App Name>.plist. App will automatically show default alert message from your .plist privacy permissions String displaying there because permission message always display in default alert view so you can do one thing before access camera show yours custom alert then redirect to camera/gallery view.
Before accessing camera you can show like this(Example contain only)

How to call a song in didMoveToView(), once, when switching through several view controllers?

I'm having a similar question to the one this fellow asked a year ago. The difference is that I am unable to fix it.
How can I continuously play background music while switching to different views using swift?
A user answered his question with this:
"You can start and stop your music from AppDelegate... The best way would be to create a MusicPlayer Class, instantiate it in AppDelegate and call start and stop methods in it...
Do you have enough experience to write something like that?
Or should I help you?"
Perhaps I need to edit app delegate? Below is what my viewDidLoad function looks like. It is where I call the audio, but every time I load the view controller it will load and play the song in addition to the first time it was loaded. How can I play a song that will be loaded in the view controller and play while the app is running, regardless of which view I am in?
override func viewDidLoad() {
super.viewDidLoad()
let path = NSBundle.mainBundle().pathForResource("Theme", ofType: "wav")
let soundURL = NSURL(fileURLWithPath: path!)
do {
try theme = AVAudioPlayer(contentsOfURL: soundURL)
theme.prepareToPlay()
} catch let err as NSError {
print(err.debugDescription)
}
// trying to make the music refrain from playing simultaneously
if !theme.playing {
theme.play()
}
theme.numberOfLoops = -1
}
Just put all of that audio player code in your app delegate file within the didFinishLaunchingWithOptions method. That will play the audio file only once when the app first starts and forever until told not to.

UIImagePickerController - Let user choose between camera and album?

In my app I have the ability for the user to take a photo and post it to a web service. I use the following code:
imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = .Camera
presentViewController(imagePicker, animated: true, completion: nil)
However, I would prefer to give the user the option to either take a photo with their camera or pick a photo from the album. I know I can choose sourceType = .PhotoLibrary but that again rules out the camera as a possible source. Is there no combination here that can give me both?
Thanks!
You can use a UIAlertController to present an alert with style UIAlertControllerStyle.ActionSheet, giving those both as choices.
This is like how Apple does it when you choose to add a photo to a text message in the Messages app, and is used in other apps as well to provide this choice, so this is obviously the most official method available for doing this. But you won't find a way to just present a UIImagePickerController that lets you choose.

Crash when choosing from the iphone photo album using monotouch

My application crashes completely (fatal error), showing the entire stacktrace and "Error connecting stdout and stderr. The weird thing is though, if I do not shut down the iPhone simulator, and I go through the workflow on my app a second time, there is no crash.
I tried both PhotoLibrary and SavedPhotosAlbum;
When picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary, everything works fine until it brings up the photo library. When you click the photo library to see the images inside, this is when the crash occurs.
When picker.SourceType = UIImagePickerControllerSourceType.SavedPhotosAlbum, the album loads fine, and I can even select an image. After I select an image, I can edit the image, etc...Once I'm done and hit Choose. It crashes.
Again, after it crashes, I can go through the workflow and it gets through just fine.
This is very strange. Any ideas?
Thanks.
I had this exact same problem; it turns out the ImagePickerController object was being garbage collected, are you declaring the property inside of a method (e.g. a button touch event?). I found if I declared the property at the start of the class then it solved this problem. Code sample:
UIImagePickerController picker;
//snip
void HandlePhotoBtnTouchUpInside(object sender, EventArgs e)
{
picker = new UIImagePickerController();
ImagePickerDelegate imgDel = new ImagePickerDelegate();
picker.Delegate = imgDel;
picker.SourceType = UIImagePickerControllerSourceType.PhotoLibrary;
PresentModalViewController(imagePicker, true);
}
The ImagePickerDelegate Class is pretty simple, I've only overridden the FinishedPickingMedia method.