yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
890 stars 131 forks source link

Sharing Image to Facebook (iOS) does not share the image just the text and link #151

Open lejeanf opened 1 year ago

lejeanf commented 1 year ago

The image is created and stored on the device. That part is no problem. Sharing to other social media like instagram works fine. Sharing to Facebook under Android works find. Sharing to Facebook under iOS does not work.

here is the code related to the sharing part:

string imageName = $"IHaveBeenThere_{(int)rect.width}x{(int)rect.height}_{System.DateTime.Now}.png";
        string filePath = Path.Combine(Application.temporaryCachePath, imageName);
        File.WriteAllBytes(filePath, screenShot.EncodeToPNG());

        NativeGallery.Permission permission = NativeGallery.SaveImageToGallery(screenShot, "I Have Been There", imageName, (success, path) => Debug.Log("Media save result: " + success + " " + path));

        // To avoid memory leaks
        Destroy(screenShot);

        new NativeShare().AddFile(filePath)
            .SetTitle("I Have Been There")
            .SetSubject(gameName).SetText(shareMessage).SetUrl("https://chunhuacatherinedong.com/")
            .SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget))
            .Share();
yasirkula commented 1 year ago

I wouldn't include DateTime in the filename as is because it might contain invalid filename characters but lucky for you, somehow it didn't seem to happen. I'd still recommend testing the code with a simpler filename like "TestImage.png", maybe Facebook sharing fails when filepath contains certain characters.

What happens when you share to Facebook on iOS? The app doesn't freeze, right? Does the image appear in share dialog but after clicking Share, it disappears or does something else happen?

lejeanf commented 1 year ago

Okay I will try that. When I share nothing crashes, it "shares" the post to facebook but when I go to facebook no image was passed through...

yasirkula commented 1 year ago

Can you also try sharing only an image (no text or url)?

UmberFunk commented 1 year ago

I have the same problem, but on both, Android and iOS.

On iOS, the same problem that lejeanf described. On Android, nothing is displayed, nor image, nor text. Other apps that I checked work well.

About a couple of weeks ago it was working well on both. Tried from several phones. Older and newer ones too. It worked on the newest iPhones too.

Might be some changes in Facebook?

yasirkula commented 1 year ago

Yeah that's my assumption as well. Can you try sharing content from Gallery, Notes, SMS, etc. apps to Facebook and see what happens?

UmberFunk commented 1 year ago

Good idea. Seems like a Facebook bug.

I get the same problem when sharing from Gallery and Notes. Share doesn't work even from Instagram. I tried to share an image from Instagram chat and had the same problem.

Websites and Youtube videos are shared normally.

I don't know if it is related, but anyway I want to note it here. On the bottom part of the screen, there is a popping-up message - "Unable to share to Reels. To share this content, create a post." I am creating a post. Not Reel. I get this message when sharing from Youtube too.

yasirkula commented 1 year ago

I've seen someone else encountering the same message and I'm hoping this isn't NativeShare related (the fact that YouTube also has this issue is actually assuring 😏).

kurisunoob commented 1 year ago

I have the same problem, just facebook does not share the image just the text and link on IOS I found remove link then image work

lejeanf commented 1 year ago

Has anyone found a solution or workaround?