yasirkula / UnityNativeShare

A Unity plugin to natively share files (images, videos, documents, etc.) and/or plain text on Android & iOS
MIT License
891 stars 131 forks source link

Unable to share videos on iOS to Instagram #105

Closed dayliff-svr closed 3 years ago

dayliff-svr commented 3 years ago

The issue: When sharing videos on iOS the share dialog get stuck, and you can't go back to the experience. Either the app becomes non-clickable with black bars around the edges, or the uploading screen displays and doesn't go away. The only way to recover from this state is to close and reopen the app.

I know Instagram is really picky with what videos you can upload, so I'm not concerned that videos can't be shared all the time. I'm trying to add a way to force hide the share dialog. I was planning on hooking it up to the OnApplicationFocus method within my application.

yasirkula commented 3 years ago

You can try adding the following to NativeShare.mm:

extern "C" void _Dismiss_View()
{
    UIViewController *view = [UnityGetGLViewController() presentedViewController];
    if( view != nil )
        [view dismissViewControllerAnimated:NO completion:nil];
} 

Then calling it with:

#if !UNITY_EDITOR && UNITY_IOS
[System.Runtime.InteropServices.DllImport( "__Internal" )]
private static extern void _Dismiss_View();
#endif

void Blabla()
{
#if !UNITY_EDITOR && UNITY_IOS
    _Dismiss_View();
#endif
}

If that doesn't work, I'm out of ideas.

dayliff-svr commented 3 years ago

BAM! Exactly what I was looking for. Thank you for your help.

yasirkula commented 3 years ago

You are welcome. Happy to hear that it worked 🕺