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

Gray Texture And Callback Not Work On Some IOS Devices #144

Open karadot opened 2 years ago

karadot commented 2 years ago

Ekran Resmi 2022-05-27 11 42 55 Description of the bug

Attached file on some ios devices shown as gray textures(13 Pro Max, X) and callback not working (X)

Reproduction steps Used code block for save:

    RectTransform rt = frame.GetComponent<RectTransform>();

    Vector3[] corners = new Vector3[4];
    rt.GetWorldCorners(corners);
    for (int i = 0; i < corners.Length; i++)
    {
        corners[i] = RectTransformUtility.WorldToScreenPoint(null, corners[i]);
    }
     //Also Used but nothing changed
    //Texture2D ss = new Texture2D((int) (corners[3].x - corners[0].x), (int) (corners[1].y - corners[0].y),TextureFormat.RGB24, false);
    Texture2D ss = new Texture2D((int) (corners[3].x - corners[0].x), (int) (corners[1].y - corners[0].y));
    ss.ReadPixels(new Rect(corners[0].x, corners[0].y, corners[3].x - corners[0].x, corners[1].y - corners[0].y), 0,
        0);
    ss.Apply();

    string filePath = Path.Combine(Application.temporaryCachePath, "shared img.png"); //temporaryCachePath
    File.WriteAllBytes(filePath, ss.EncodeToPNG());

    // To avoid memory leaks
    Destroy(ss);

    new NativeShare().AddFile(filePath)
        .SetText("Can you beat my score?")
        .SetUrl(url)
        .SetCallback((result, shareTarget) =>
        {
            shareResult = true;
        })
        .Share();
    yield return new WaitUntil(() => shareResult);

Platform specs

Please provide the following info if this is a Unity 3D repository.

yasirkula commented 2 years ago

Can you assign the texture (ss) to a RawImage to verify that the problem doesn't originate from the Texture itself? Can you also put a Debug.Log inside SetCallback and verify that it isn't called? Can you also check for any error logs?

karadot commented 2 years ago

I can verify SetCallback not working because I set shareResult in it, and wait it for it to became true. I tried app on IPhone SE, it worked correctly. I will assign texture to RawImage when I return to working on project, and let you know.

yasirkula commented 2 years ago

Thank you. Regardless, please add a Debug.Log to SetCallback, thanks!