You should refactor this as the screen capture may not be complete before you try to use it. Personally, I’m not sure how async it is and how long capturing the screen could take, so that may not be the issue. By the way that the capture screenshot function has a callback for when it’s completed, I’m guessing it isn’t instantaneous.
Regardless I’d say that when the twitterbutton is pressed, you should capture the screen contents. Then, in the callback afterCapture(), if it was successful you should share the screenshot, otherwise you could either fallback to sharing some text or show an alert dialog to say that sharing failed.
You should not be calling the sharing code in the same place as capturing the screenshot, as currently you have no idea if the image object contains data or if it was successful or not.
Some quick pseudocode would be:
button->addTouchEventListener() {
captureScreenShot(withAmazingCallback:, andImageName:)
// DO NOT SHARE THE SCREENSHOT HERE!
}
...
void amazingCallback(success, output) {
if success {
// share image here instead!
} else {
// fallback to text, or show error alert
}
}
I’m also unsure on how the CC_CALLBACK_2 callbacks work, so also ensure that your callback is being called correctly and image data is being received.
The pseudocode I gave above is exactly that: pseudocode. I was rather tired last night, hence I didn’t type in any code for you, the pseudocode is there to simply guide you in changing your own code.
To put it simply:
Move the sharing code from where you capture the screenshot (the button touch listener) to where you receive the results of the screenshot capture (the callback you showed in your example).
If the screenshot was successful, share it. Otherwise, fallback to just text or nothing at all.
Ensure your callback gets called correctly with the right parameters.
If the screenshot function says it’s failing every time, your problem is with the function or potentially the callback, although you should investigate that if the refactoring does not work.
Screen capture is successful. I tried adding the capture image and succeeded. But when sharing via twitter is not.
I will try using EziSocial. But this plugin has been deleted.
What do you have solution to share image via twitter?
Thank you !!