How to wait till the screenshot is saved?

Hello,

I’m trying to implement screenshot sharing in my game and I’m facing the following problem right now: when I want to share a screenshot via Activity Sheet in iOS the screenshot is not yet saved at this moment (when I call Share function the screenshot is not yet saved) and I’m only able to share a screenshot that was taken previously when I try to share for the second time. How can I wait till the screenshot is saved in file and call a function only at the moment when it is saved?
Here’s my code:

    public class NativeShare : MonoBehaviour {
    	public string ScreenshotName = "screenshot.png";
    	public string ShareText = "";
    	private string pathToImage;
    
        public void ShareScreenshotWithText()
    	{
    		ShareText =  "Some text";
    		Application.CaptureScreenshot(ScreenshotName);
    		string pathToScreenshot = Application.persistentDataPath + "/" + ScreenshotName;
    		Share (ShareText, pathToScreenshot, "");
        }

        ...

    }

I’ve found several answers to this question on the forums but none of them worked for me. Thanks.

Try this :

Use coroutine to wait before using newer screenshot.

public void ShareScreenshotWithText()
	{
		StartCoroutine(ShareScreenshotWithTextEnumerator());
	}

	IEnumerator ShareScreenshotWithTextEnumerator()
	{
		ShareText =  "Some text";
		Application.CaptureScreenshot(ScreenshotName);
		string pathToScreenshot = Application.persistentDataPath + "/" + ScreenshotName;
		yield return new WaitForSeconds(1);//wait before use new screenshot
		Share (ShareText, pathToScreenshot, "");
	}