I am using SwiftUI, and I am trying to use share sheet to share image from my app to other apps. I found that my image could send to every native app in iPhone such as message, email and the image could be saved to local picture app, but for any other app, it would have a sort of buggy response, like WeChat, WhatsApp. When I chose to share the image in these apps, I could tell that there was a screen popping up but the screen would not be shown fully, leaving a transparent background. And they just freeze there.
My code below:
Button {
actionSheet()
} label: {
Image(systemName: "arrowshape.turn.up.forward.fill")
.foregroundColor(.primary)
.font(.title)
}
func actionSheet(){
guard let data = UIImage(named: LOCAL_IMAGE_NAME) else { return }
let activityVC = UIActivityViewController(activityItems: [data], applicationActivities: nil)
guard var topVC = UIApplication.shared.windows.first?.rootViewController else {
return
}
while let presentedVC = topVC.presentedViewController {
topVC = presentedVC
}
topVC.present(activityVC, animated: true)
}
class ImageSharing: UIActivityItemProvider {
var image: UIImage
override var item: Any {
get {
return self.image
}
}
override init(placeholderItem: Any) {
self.image = (placeholderItem as? UIImage) ?? UIImage(imageLiteralResourceName: LOCAL_DEFAULT_IMAGE_NAME)
super.init(placeholderItem: image)
}
override func activityViewControllerLinkMetadata(_ activityViewController: UIActivityViewController) -> LPLinkMetadata? {
let metadata = LPLinkMetadata()
metadata.title = "Result Image"
var thumbnail: NSSecureCoding = NSNull()
if let imageData = self.image.pngData() {
thumbnail = NSData(data: imageData)
}
metadata.imageProvider = NSItemProvider(item: thumbnail, typeIdentifier: "public.png")
return metadata
}
}
Error I got
2022-11-05 10:20:05.473939+0800 Art[86987:3055636] [default] LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-11-05 10:20:05.473995+0800 Art[86987:3055636] [default] Attempt to map database failed: permission was denied. This attempt will not be retried. 2022-11-05 10:20:05.474041+0800 Art[86987:3055636] [db] Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={NSDebugDescription=process may not map database, _LSLine=264, _LSFunction=-[_LSDReadClient getServerStoreWithCompletionHandler:]}
2022-11-05 10:20:05.475647+0800 Art[86987:3055636] [default] -imageForImageDescriptor: can do IO please adopt -imageForDescriptor: for IO free drawing or -prepareImageForDescriptor: if IO is allowed. (This will become a fault soon.)
2022-11-05 10:20:05.931981+0800 Art[86987:3055636] [NSExtension] Extension request contains input items but the extension point does not specify a set of allowed payload classes. The extension point's NSExtensionContext subclass must implement
+_allowedItemPayloadClasses
. This must return the set of allowed NSExtensionItem payload classes. In future, this request will fail with an error.
2022-11-05 10:20:09.130698+0800 Art[86987:3059978] [lifecycle] [u 9BD42A51-1893-4F2F-A2A5-544026125870:m (null)] [net.whatsapp.WhatsApp.ShareExtension(22.21.77)] Connection to plugin interrupted while in use.
2022-11-05 10:20:09.131103+0800 Art[86987:3057447] [lifecycle] [u 9BD42A51-1893-4F2F-A2A5-544026125870:m (null)] [net.whatsapp.WhatsApp.ShareExtension(22.21.77)] Connection to plugin invalidated while in use.
2022-11-05 10:20:09.131729+0800 Art[86987:3055636] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
2022-11-05 10:20:09.131789+0800 Art[86987:3055636] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}