0

Before iOS 11 came out I created a share extension to my social media app. It worked perfectly fine. Once iOS 11 came out, the share extension quit working. I searched and debugged the extension until I found the source of the problem. When looping through the attachments inside the extensionContext.inputItems[0].attachments, none of the attachments has an item conforming to kUTTypeImage. So none of my code was running from that point on. I also had another strange outcome yesterday. This is part of my code inside the didSelectPost function.

    guard let content = extensionContext?.inputItems[0] as? NSExtensionItem else { return }
    guard let contentAttachments = content.attachments as? [NSItemProvider] else { return }

    let skyName = self.textView.text

    for attachment in contentAttachments {
        if attachment.hasItemConformingToTypeIdentifier(imageType) {
            attachment.loadItem(forTypeIdentifier: imageType, options: nil) { (data, error) in

                guard error == nil, let url = data as? NSURL else { return }
                self.imageFromAsset(url: url as URL)
                if !self.selectedType.isEmpty {
                    do {
                        let imageData = try Data(contentsOf: url as URL)
                        self.skyImage = UIImage(data: imageData)

                        self.saveSkyImage()

                        guard let skyOriginalImageURL = self.skyOriginalImageURL else { return }
                        guard let skyImageURL = self.skyImageURL else { return }

                        let newSky = Sky(name: skyName ?? "Another Sky",
                                         type: self.selectedType,
                                         date: self.date,
                                         location: self.location,
                                         picture: CKAsset(fileURL: skyImageURL),
                                         likes: 0, flags: 0,
                                         likedBy: [CKReference](), flaggedBy: [CKReference](),
                                         originalImage: CKReference(record: CKRecord(recordType: "SkyImage"), action: .none))
                        let newSkyImage = SkyImageFullResolution(picture: CKAsset(fileURL: skyOriginalImageURL))
                        self.saveSky(sky: newSky, skyImage: newSkyImage)
                    } catch {
                        print(error.localizedDescription)
                        self.closePostWindow()
                    }
                }
            }
        }
    }

    defer {
        closePostWindow()
    }
Grant Emerson
  • 404
  • 1
  • 4
  • 13

1 Answers1

1

I don't have a direct answer to your problem but recently in iOS 11 I have resolved a problem to display a share extension involving PDF files.

My problem was that my expected type identifiers were not found among the attachments.

NSItemProvider has an instance property registeredTypeIdentifiers to show you the type identifiers that can be found when your extension is activated.

That's what I do : 1) I use TRUEPREDICATE as NSExtensionActivationRule to force display my share extension in the context of my interest. 2) After you select your share extension, your extension code will be triggered. Then you print all the type registeredTypeIdentifiers of each attachment, by looping through your contentAttachments.

Once you have identified all the identifiers, you will be able to find a solution to your problem.

Rasalghul
  • 71
  • 7