- Home /
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.
Answer by KuR5 · Jun 10, 2016 at 09:38 AM
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, "");
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612081327im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Native Sharing dialog cause crash on iPad 2 iOS 7.1.2 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How Can I Generate a Thumbnail from the Screen? 2 Answers
Returning a byte array from ObjC to C# script on ios 2 Answers