UIActivityViewController crashing iOS 10

Hi,


I have a very simple image gallery app with a share button in the nav bar. When pressed it should show a popover to share, email etc. the image. The popover presents fine, but as soon as you press 'Save Image' the app crashes and it's very unclear why.


Here's the code that presents the controller:


    @IBAction func shareButton(_ sender: UIBarButtonItem) {
        print("Share button pressed")
      
        if let animal = animal {
            let avc = UIActivityViewController.init(activityItems: [animal.image], applicationActivities: nil)
          
            avc.popoverPresentationController?.barButtonItem = sender
            self.present(avc, animated: true) {
                print("completed")
            }
        }
    }

Accepted Reply

This is a easy answer, which I should have noticed earlier. I had not yet added NSPhotoLibraryUsageDescription to my Info.plist. Once I added it, things work.


Thanks for your time.


(edit: formatting)

Replies

Do you get a stacktrace or something, when running the app in Xcode?


I stumbled accross a crash recently 'by accident' when "Save PDF to iBooks" is touched. It happens some inside UIKit (according to the stacktrace shown in Xcode), so currently I assume a bug in iOS.


So what happens, if your run this code in Xcode with a debugger attached?


Dirk

Hi Dirk,


Sorry for the delayed response. Here is the stack trace that happens after clicking 'save image'.


Share button pressed
2016-07-21 15:49:55.501933 Galleria Animalia[865:29393] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /private/var/containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-07-21 15:49:56.077701 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToTwitter => com.apple.share.Twitter.post
2016-07-21 15:49:56.077753 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFacebook => com.apple.share.Facebook.post
2016-07-21 15:49:56.077776 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToWeibo => com.apple.share.SinaWeibo.post
2016-07-21 15:49:56.077797 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.TencentWeibo => com.apple.share.TencentWeibo.post
2016-07-21 15:49:56.077816 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToFlickr => com.apple.share.Flickr.post
2016-07-21 15:49:56.077837 Galleria Animalia[865:29393] [core] SLComposeViewController extensionIdentifierForActivityType: com.apple.UIKit.activity.PostToVimeo => com.apple.share.Vimeo.post
2016-07-21 15:49:56.109317 Galleria Animalia[865:29393] [MC] Reading from public effective user settings.
2016-07-21 15:49:56.442208 Galleria Animalia[865:29393] [MC] Filtering mail sheet accounts for bundle ID: net.huwr.Galleria-Animalia, source account management: 1
2016-07-21 15:49:56.445225 Galleria Animalia[865:29393] [MC] Result: YES
2016-07-21 15:49:56.445281 Galleria Animalia[865:29393] [MC] Filtering mail sheet accounts for bundle ID: net.huwr.Galleria-Animalia, source account management: 1
2016-07-21 15:49:56.445663 Galleria Animalia[865:29393] [MC] Result: YES
completed
2016-07-21 15:49:58.841798 Galleria Animalia[865:29439] [access] <private>
Post not yet marked as solved Up vote reply of huwr Down vote reply of huwr

This is a easy answer, which I should have noticed earlier. I had not yet added NSPhotoLibraryUsageDescription to my Info.plist. Once I added it, things work.


Thanks for your time.


(edit: formatting)