Search Unity

Native Share for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Mar 1, 2018.

Thread Status:
Not open for further replies.
  1. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    114
    Thanks for the great Plugin. I had this all working nicely on Android and iOS, however, suddenly I got an issue on iOS. I'm on a iPhone X with latest iOS 13.x.
    The first time I call NativeShare in my app it works as expected. Subsequent times, the Native Share panel comes up, but is empty, no sharing options just a blank grey panel. Works again only if I quit the app and restart the phone.

    I'm not using anything fancy just:
    new NativeShare().AddFile(pathAndFilename).SetSubject("subject blah blah").SetText("").SetCallback((result, shareTarget) => Debug.Log("Share result: " + result + ", selected app: " + shareTarget)).Share();

    Any idea?
     
  2. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Does omitting SetSubject and SetText change anything? Are there any error messages in Xcode console?
     
  3. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    548
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd like to stick with Android & iOS platforms only but thank you for the suggestion!
     
  5. Marks4

    Marks4

    Joined:
    Feb 25, 2018
    Posts:
    548
    cries in jslib plugin
     
    yasirkula likes this.
  6. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    new NativeShare().AddFile(filePath).Share();
    I'm using this to share image / video. There's multiple issues I'm having on iOS.
    - I'm unable to share video on some devices
    - On some devices some apps don't even show up in the list of applications

    Am I missing something?
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Your code looks OK. I'm assuming that it doesn't contain SetText or SetSubject functions. I'd recommend you to check out Xcode logs for anything suspicious.
     
  8. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    Yes! It doesn't contain SetText or SetSubject functions.

    This is on iPhone X and on some iPads...iPhone 11 & iPhone 7 worked. The only difference is the iPhone X is on iOS 12...but I've heard from other users that they were on iOS 13 and still wasn't working.

    Error log with the call back:

    Code (CSharp):
    1. 2020-10-07 13:33:31.586735-0500 PumpkinCarvingARF[1807:779598] [default] [ERROR] Failed to determine whether URL /var/mobile/Containers/Data/Application/AAD8E19D-29EB-435A-9700-63590612EF5E/Documents/recording_2020_10_07_13_30_38_862.mp4 (n) is managed by a file provider
    2. 2020-10-07 13:33:41.391519-0500 PumpkinCarvingARF[1807:777823] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
    3. 2020-10-07 13:33:41.391716-0500 PumpkinCarvingARF[1807:777823] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
    4. 2020-10-07 13:33:41.448553-0500 PumpkinCarvingARF[1807:777823] Shared to com.burbn.instagram.shareextension with result: 0
    5. Share result: NotShared, selected app: com.burbn.instagram.shareextension
    6. <>c:<ShareFile>b__21_0(ShareResult, String)
    7. ShareResultCallback:Invoke(ShareResult, String)
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I wonder if sharing from other apps to Instagram also yield the same error. Because there is a slim chance that it is an iOS bug. Otherwise, perhaps the mp4 file wasn't completely written to the disk (i.e. the file stream was still open) while sharing it. You can try waiting a few seconds in a coroutine before sharing the file to see if it makes any difference.
     
  10. iB_Gaming

    iB_Gaming

    Joined:
    Apr 13, 2020
    Posts:
    10
    Hello @yasirkula,

    First off, thanks for the plugin.

    I have a weird issue with it, though, was wondering if it's been documented already. When taking a screenshot (via ReadPixels or CaptureScreenshotAsTexture, after waiting for end of frame) and sharing it, iPhone XS returns it with a white semi-transparent filter over it, causing the image to look very bleak, while an iPad Air 2 running the same version of iOS (13.7) shares a crystal clear image. Any idea what might be causing it?
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I haven't heard about this issue before. Can you create a Texture from the screenshot using Texture2D.LoadImage and display it in a RawImage to see if the screenshot itself has this issue?
     
  12. iB_Gaming

    iB_Gaming

    Joined:
    Apr 13, 2020
    Posts:
    10
    Can I ask you to elaborate a bit on what you're asking to do? LoadImage (from what I understand it's under ImageConversion now) takes a texture (that of a RawImage component, in our case) and fills it with some byte data. How do I turn a screenshot into a byte array? I'm quite new to this, the only way I'm aware of is via some sort of serialization, like with a BinaryFormatter.
     
  13. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You already have a screenshot that you are passing to NativeShare. You'll just need to call File.ReadAllBytes on that path and pass those bytes to LoadImage.
     
  14. Suwas93

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    62
    I'm sharing it long after It's saved.
     
  15. DryHeat

    DryHeat

    Joined:
    Jul 31, 2012
    Posts:
    4
    NativeShare seems to work great! I do have an issue when sharing a video to slack on iOS. It does share successfully, but then the native share overlay never seems to close after it shares. The app just looks like it hangs.

    My share call is simple enough.

    new NativeShare().AddFile(videoFileName).Share();
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    @Suwas93 Does sharing from e.g. WhatsApp to Instagram or Photos to Instagram also yield the same error?

    @DryHeat I've heard that this is Slack app's behaviour and sharing media from other apps to Slack also suffer from the same issue.
     
  17. iB_Gaming

    iB_Gaming

    Joined:
    Apr 13, 2020
    Posts:
    10
    Tried it, and the screenshot itself has this pale overlay, so it's not related to Native Share. If you have any ideas why it could be happening on an iPhone and not on an iPad, I'd appreciate any help.
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    The example screenshot code has been working fine for me. If it also has the same issue, I unfortunately don't know why this issue is occurring. Probably a post-processing effect is causing the issue.
     
  19. iB_Gaming

    iB_Gaming

    Joined:
    Apr 13, 2020
    Posts:
    10
    Yeah, that's the one I've been using to take screenshots. Still, thanks for the feedback.
     
  20. cadrick

    cadrick

    Joined:
    Jul 23, 2016
    Posts:
    9
    Wanna ask are these permissions required for saving/sharing pictures?

    READ_EXTERNAL_STORAGE
    WRITE_EXTERNAL_STORAGE
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    They aren't needed.
     
  22. cadrick

    cadrick

    Joined:
    Jul 23, 2016
    Posts:
    9
    Thanks!
     
  23. l3mon

    l3mon

    Joined:
    Jan 25, 2016
    Posts:
    21
    Thanks for the great plugin!

    I went through the problem with either text or image and went for image.
    For me, setting the file and subject worked perfectly.
    (I'm not setting the text in general or title for Android)

    Code (CSharp):
    1.         // Set content
    2.         shareObj.AddFile(pathName);
    3.         shareObj.SetSubject(shareText);
    4.  
    5.         shareObj.Share();
    6.  
    However on one Android test device, WhatsApp says can't send emtpy messages.
    Once I enter a text, it works, but the image is discarded as already known.

    Tried with shareObj.SetText(""); but that didn't work.

    Most test devices don't have that issue.
    Any advice? Have you come across this before?
     
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I don't think I have. Perhaps WhatsApp isn't up-to-date on that device?

    P.S. Does omitting subject help?
     
    Last edited: Oct 21, 2020
  25. l3mon

    l3mon

    Joined:
    Jan 25, 2016
    Posts:
    21
    Without subject leads to the same result

    It’s the latest version from Google Play. However it was updated manually to the last version, but with same result...
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    As much as I want to help, I don't know what is causing this issue on that particular Android device or how it can be resolved :/
     
  27. chibatribe

    chibatribe

    Joined:
    Jan 2, 2017
    Posts:
    3
    Hello YasirKula, your plugin is fantastic, I have implemented that in android and working perfectly, now I have to do in ios. So can you please tell me how to share my text and image to a specific app like whatsapp,facebook,insta. as i have prebuilt buttons for each platforms. Thank you
     
    yasirkula likes this.
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please see the relevant FAQ entry here. I'd also recommend you to take a look at the "I can't share image with text on X app" FAQ entry, just in case.
     
  29. chibatribe

    chibatribe

    Joined:
    Jan 2, 2017
    Posts:
    3
    Hello Yasirkula, thank you for your reply, I need to make my question clear.
    I don't have problem with sharing only image. What I need is to be able to share to a specific app as i made buttons for each app. like using addTarget() in android, it's not working for ios please give some guidance on that.I have searched a lot on internet and end up on getting only android tutorials. Thank you for your time :)
     
  30. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  31. chibatribe

    chibatribe

    Joined:
    Jan 2, 2017
    Posts:
    3
    sorry for asking lot of doubts... i dont really know the working of the nativeshare.mm so where should i pass the int values
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  33. Lu_Atar

    Lu_Atar

    Joined:
    May 16, 2017
    Posts:
    8
    Hello Yasirkula, thank you very much for for creating and making Native available. I have a question: as I understand it, one can share text and images inside a unity app to all apps that support sharing. Is it possible vice versa? E.g. can one make a unity app appear in the Share panel when say I want to share a YouTube link?
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can't do it with NativeShare but with other plugins like this.
     
    M_G_L likes this.
  35. M_G_L

    M_G_L

    Joined:
    Apr 4, 2017
    Posts:
    7
    Hi Yasirkula,

    Thanks for this plugin.

    Is there a way to display the captured screenshot into an UI image, please? Sorry for this noob question. I'm very new to this.

    You said: "You'll just need to call File.ReadAllBytes on that path and pass those bytes to LoadImage."

    Code (CSharp):
    1. File.ReadAllBytes(imagePath);
    I don't understand this part: pass those bytes to LoadImage.

    Can you post an example please?

    My goal is to display the captured screenshot in an UI image with a share button under the image.

    Thanks in advance!

    Kind Regards,
    John
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You can call these TakeScreenshot and ShareButtonClicked functions:
    Code (CSharp):
    1. public Image imageObject;
    2. private Texture2D screenshot;
    3.  
    4. public void TakeScreenshot()
    5. {
    6.     StartCoroutine( TakeScreenshotCoroutine() );
    7. }
    8.  
    9. private IEnumerator TakeScreenshotCoroutine()
    10. {
    11.     yield return new WaitForEndOfFrame();
    12.  
    13.     // Destroy previous screenshot (if any)
    14.     Destroy( screenshot );
    15.    
    16.     screenshot = new Texture2D( Screen.width, Screen.height, TextureFormat.RGB24, false );
    17.     screenshot.ReadPixels( new Rect( 0, 0, Screen.width, Screen.height ), 0, 0 );
    18.     screenshot.Apply();
    19.    
    20.     Sprite sprite = Sprite.Create( screenshot, new Rect( 0f, 0f, screenshot.width, screenshot.height ), new Vector2( 0.5f, 0.5f ), 100f );
    21.    
    22.     // Assign sprite to Image
    23.     imageObject.sprite = sprite;
    24. }
    25.  
    26. public void ShareButtonClicked()
    27. {
    28.     string filePath = Path.Combine( Application.temporaryCachePath, "Screenshot.png" );
    29.     File.WriteAllBytes( filePath, screenshot.EncodeToPNG() );
    30.  
    31.     new NativeShare().AddFile( filePath ).Share();
    32. }
     
    M_G_L likes this.
  37. M_G_L

    M_G_L

    Joined:
    Apr 4, 2017
    Posts:
    7
    AMAZING!!!
    Thank you very much Yasirkula! You're awesome!

    I've tested the script in a build on my android device and it works very nice! :)
     
    yasirkula likes this.
  38. unity_cic-PNqQMQ9LKA

    unity_cic-PNqQMQ9LKA

    Joined:
    Oct 30, 2020
    Posts:
    6
    Awesome, thanks for the tip!
     
  39. DryHeat

    DryHeat

    Joined:
    Jul 31, 2012
    Posts:
    4
    I'm having trouble sharing to instagram on iOS. I'm using the screenshot example above that you provided. It works fine when sharing to the other platforms, but I get these errors when trying instagram. I know it was working in the past, but I believe it may have stopped working after upgrading to Unity 2020. Is anyone else using Unity 2020?

    2020-11-04 15:21:23.630654-0800 xxxxxx[20266:1807400] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x2839aed00> (Domain: com.apple.Sharing, User: kCFPreferencesCurrentUser, ByHost: No, Container: kCFPreferencesNoContainer, Contents Need Refresh: Yes): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access

    2020-11-04 15:21:23.631180-0800 xxxxxx[20266:1807400] [User Defaults] Couldn't read values in CFPrefsPlistSource<0x2839aed00> (Domain: com.apple.Sharing, User: kCFPreferencesCurrentUser, ByHost: No, Container: kCFPreferencesNoContainer, Contents Need Refresh: Yes): accessing preferences outside an application's container requires user-preference-read or file-read-data sandbox access

    2020-11-04 15:21:23.633202-0800 xxxxxx[20266:1807400] <CATransformLayer: 0x281600920> - changing property backgroundColor in transform-only layer, will have no effect

    2020-11-04 15:21:30.257596-0800 xxxxxx[20266:1807933] [lifecycle] [u EC573999-2104-409A-8C86-67DE614B77A6:m (null)] [com.burbn.instagram.shareextension(165.0)] Connection to plugin interrupted while in use.

    2020-11-04 15:21:30.258624-0800 xxxxxx[20266:1807809] [lifecycle] [u EC573999-2104-409A-8C86-67DE614B77A6:m (null)] [com.burbn.instagram.shareextension(165.0)] Connection to plugin invalidated while in use.

    2020-11-04 15:21:30.258647-0800 xxxxxx[20266:1807400] [core] HOST: Failed to load remote view controller with error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 20272 named com.burbn.instagram.shareextension.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service on pid 20272 named com.burbn.instagram.shareextension.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}


    2020-11-04 15:21:30.258891-0800 xxxxxx[20266:1807400] [core] Sheet not being presented, calling premature completion


    2020-11-04 15:21:30.258994-0800 xxxxxx[20266:1807400] Shared to com.burbn.instagram.shareextension with result: 0
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I couldn't find any useful results on Google and couldn't figure out the possible cause of this issue by looking at the error messages. Unfortunately, I don't have access to my Mac workstation for a while either, so it will take some time to reproduce the issue. In the meantime, I'd recommend you to create an Issue on GitHub: https://github.com/yasirkula/UnityN...ees=&labels=bug&template=bug_report.md&title=
     
  41. AshMXR

    AshMXR

    Joined:
    Sep 23, 2020
    Posts:
    1
    hey @yasirkula have worked with your plugin in the past. works well. wondering now if your plugin works in a webGL build. recently ran into issues using the native html way of navigator.share().
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Only Android and iOS platforms are supported.
     
  43. afmj

    afmj

    Joined:
    Sep 29, 2017
    Posts:
    4
    I have an app where i have deep linking enabled, is it posible to send a link it to whatsapp so that when the user clicks on the link the app opens?
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I think so. Did you try passing the link to SetText function?
     
  45. gabdab2017

    gabdab2017

    Joined:
    Nov 27, 2017
    Posts:
    4
    Social sharing not working (Unity 2020.1.9f1 - Linux) only after compiling as Build App Bundle (Google Play ..)..?
    Subsequent .apk won't work, note base.apk not available in non-bundle compilation, but search path..

    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.yasirkula.unity.NativeShare" on path: DexPathList[[zip file "/data/app/com.Gabgames.Knhop-SZeGgijYmB2w9_kt4VE-pg==/base.apk"],nativeLibraryDirectories=[/data/app/com.Gabgames.Knhop-SZeGgijYmB2w9_kt4VE-pg==/lib/arm, /data/app/com.Gabgames.Knhop-SZeGgijYmB2w9_kt4VE-pg==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]]

     
    Last edited: Nov 21, 2020
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Is ProGuard or Gradle minification enabled? If ProGuard is enabled, see the relevant entry in FAQ.
     
    gabdab2017 likes this.
  47. areavisuale

    areavisuale

    Joined:
    Jul 23, 2015
    Posts:
    60
    I had the exact same problem. It seems related to a memory leak, when I try to share a screenshot for print with this: ScreenCapture.CaptureScreenshotAsTexture(4)

    The strange thing is that if I save the image in the camera roll, then I can share it without problem. Can it be that the plugin put a limit to the image size?

    I encounter that problem with a new clean project using Unity 2020.1.14, xCode 12.2 macOs Big Sur, and iPhone X.
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I didn't put an image size limit. Can I see your code that saves the image to camera roll and then shares it?

    P.S. Oh, did you mean saving to Photos via NativeGallery, opening Photos app and then sharing the image from there?
     
    Last edited: Nov 29, 2020
  49. aholla

    aholla

    Joined:
    May 27, 2014
    Posts:
    81
    Hi is there a way to save directly to the camera roll rather than via the native share popup?
     
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
Thread Status:
Not open for further replies.