Facebook共享扩展在iOS 11中崩溃

问题描述 投票:1回答:4

我正在使用UIActivityViewController使用户能够在社交媒体上分享图像。但是,几秒钟后,Facebook的分享对话框在iOS 11中崩溃,并显示以下日志:

[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}

虽然图像需要几秒钟才能显示,但iOS 10中不会发生此错误。

知道是什么导致了这个问题吗?我是否必须等待Facebook解决这个问题?

facebook uikit ios11 ios8-share-extension
4个回答
1
投票

Facebook不再集成在iOS 11中。您可以集成本机Facebook SDK并使用以下代码:

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];

它只有在设备上安装本机Facebook应用程序(iOS 10和之前没有应用程序)时才有效,您可以检查它:

BOOL isInstalledFBApp = [[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbshareextension://"]];

有关更多信息:https://developers.facebook.com/docs/sharing/ios/


1
投票

Karen Hovhannisyan的回答是正确的。规模大于1.0的图像将导致Twitter和Facebook崩溃。缩放图像可以解决问题。然而它并不是很理想。我尝试通过增加大小来匹配分辨率来规范化图像,但这也导致了崩溃。可能是因为图像太大了。

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
}

0
投票

在与Whatsapp共享图像时,我遇到了同样的问题,几秒钟后共享对话框自动关闭。感谢@Mike Demidov,我意识到由于我保存图像的方式,要分享的图像有问题,如下所示。

if let testImage = UIImageJPEGRepresentation(self.testImageView.image!, 0.5) {

    let destinationUrl = DocumentHelper.getDocumentsDirectory().appendingPathComponent(identifier + "_test.png")

    try? testImage.write(to: destinationUrl)

}

原因是因为我使用UIImageJPEGRepresentation来转换图像,但我将图像名称/文件格式设置为.png。

我所做的就是将其更改为.jpeg,如下所示。

if let testImage = UIImageJPEGRepresentation(self.testImageView.image!, 0.5) {

    let destinationUrl = DocumentHelper.getDocumentsDirectory().appendingPathComponent(identifier + "_test.jpeg")

    try? testImage.write(to: destinationUrl)

}

希望能帮助到你!


0
投票

在可能的情况下,Facebook,Twitter和Whatsapp共享扩展程序崩溃,因为共享图像缩放属性> 1.0

© www.soinside.com 2019 - 2024. All rights reserved.