Reputation: 10383
I'm using the UIActivityViewController
to enable the user to share images on social media. However, Facebook's share dialog crashes in iOS 11 after a few seconds with the following log:
[core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
[core] SLComposeViewController remoteViewController: <SLRemoteComposeViewController: 0x1040b7e00> didTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
The error doesn't occur in iOS 10, though the image takes a few seconds to be displayed.
Any idea what's causing this issue? Do I have to wait for Facebook to fix this?
Upvotes: 2
Views: 3966
Reputation: 103
The answer from Karen Hovhannisyan is correct. Images with a scale larger than 1.0 will crash both Twitter and Facebook. Scaling the image does the trick. However its not really ideal. I tried to normalise the image by increasing the size to match the resolution, but that also caused a crash. Might be because the image was too large.
func shareableImage(image: UIImage) -> UIImage {
guard let cgImage = image.cgImage else { return image }
let size: CGSize = CGSize(width: CGFloat(cgImage.width) / image.scale, height: CGFloat(cgImage.height) / image.scale)
defer {
UIGraphicsEndImageContext()
}
UIGraphicsBeginImageContextWithOptions(size, false, 1)
image.draw(in: CGRect(origin: .zero, size: size))
return UIGraphicsGetImageFromCurrentImageContext() ?? image
}
Upvotes: 1
Reputation: 1248
In may case Facebook, Twitter and Whatsapp share extensions crashing because share image scale property is > 1.0
Upvotes: 0
Reputation: 947
I was facing the same issue upon sharing images to Whatsapp where the share dialog closes by itself after a few seconds. Thanks to @Mike Demidov, I realised that something is wrong with the images to be shared due to the way I saved the images as shown below.
if let testImage = UIImageJPEGRepresentation(self.testImageView.image!, 0.5) {
let destinationUrl = DocumentHelper.getDocumentsDirectory().appendingPathComponent(identifier + "_test.png")
try? testImage.write(to: destinationUrl)
}
The reason being is because I'm using UIImageJPEGRepresentation
to convert the image but I was setting the image name / file format as .png.
All I did to solve my issue was to change it to .jpeg as shown below.
if let testImage = UIImageJPEGRepresentation(self.testImageView.image!, 0.5) {
let destinationUrl = DocumentHelper.getDocumentsDirectory().appendingPathComponent(identifier + "_test.jpeg")
try? testImage.write(to: destinationUrl)
}
Hope it helps!
Upvotes: 0
Reputation: 507
Facebook is no longer integrated in iOS 11. You can integrate the native Facebook SDK and use this code:
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = _image;
photo.userGenerated = YES;
FBSDKSharePhotoContent *content = [[FBSDKSharePhotoContent alloc] init];
content.photos = @[photo];
[FBSDKShareDialog showFromViewController:self withContent:content delegate:self];
It works only if the native Facebook app is installed on device(iOS 10 and prior without app) and you can check it:
BOOL isInstalledFBApp = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbshareextension://"]];
For more information: https://developers.facebook.com/docs/sharing/ios/
Upvotes: 1