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

Can't share to Instagram (except Reel) in iOS 16.3.1 #169

Open stankikween opened 1 year ago

stankikween commented 1 year ago

I am trying to share a screenshot and text on iOS. I understand the limitations of sharing both a screenshot and text on certain applications, and on Facebook and Messenger the screenshot shares fine without the text included.

However, when I try to share to Instagram, after tapping the Instagram app it gives me the option to share to a Reel, Post, Story, or Message. When I select Reel it seems to work, however when I select Story or Message I get a pop-up that says "Error, Something went wrong." When I select Post I get a pop-up that says "Error, We're sorry, but something went wrong. Please try again."

I tried removing the text portion of my share so that it was just attempting to share the image, and was still getting the errors on just Instagram. Every other application I have tried (Facebook, Messenger, Slack, Teams, Email, Snapchat, etc) shares successfully.

I am using what is essentially the sample code:

` private IEnumerator TakeScreenshotAndShare() { yield return new WaitForEndOfFrame();

    Texture2D ss = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
    ss.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
    ss.Apply();

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

    // To avoid memory leaks
    Destroy( ss );

    new NativeShare().AddFile( filePath )
        .SetSubject( "Cafe Sudoku" ).SetText( shareMessage )
        .SetCallback( ( result, shareTarget ) => Debug.Log( "Share result: " + result + ", selected app: " + shareTarget ) )
        .Share();

}`

Additional info

Here is a log I got when attempting to share to my Instagram Story:

`2023-04-07 14:37:12.077694-0700 CafeSudoku[30089:2121970] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method} 2023-04-07 14:37:12.572509-0700 CafeSudoku[30089:2121970] Shared to com.burbn.instagram.shareextension with result: 0 Share result: NotShared, selected app: com.burbn.instagram.shareextension <>c:b__5_0(ShareResult, String)

2023-04-07 14:37:12.816105-0700 CafeSudoku[30089:2122385] [ShareSheet] connection invalidated`

yasirkula commented 1 year ago

Can you try applying this change to the code: https://github.com/yasirkula/UnityNativeShare/issues/22#issuecomment-404258004