Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Native Share for Android & iOS [Open Source]

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

  1. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    86
    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:
    1,724
    Does omitting SetSubject and SetText change anything? Are there any error messages in Xcode console?
     
  3. Marks4

    Marks4

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

    yasirkula

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

    Marks4

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

    Suwas93

    Joined:
    Feb 8, 2018
    Posts:
    28
    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:
    1,724
    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:
    28
    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:
    1,724
    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:
    7
    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:
    1,724
    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:
    7
    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:
    1,724
    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:
    28
    I'm sharing it long after It's saved.
     
  15. DryHeat

    DryHeat

    Joined:
    Jul 31, 2012
    Posts:
    2
    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:
    1,724
    @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:
    7
    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:
    1,724
    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:
    7
    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:
    8
    Wanna ask are these permissions required for saving/sharing pictures?

    READ_EXTERNAL_STORAGE
    WRITE_EXTERNAL_STORAGE
     
  21. yasirkula

    yasirkula

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

    cadrick

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

    l3mon

    Joined:
    Jan 25, 2016
    Posts:
    17
    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:
    1,724
    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:
    17
    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:
    1,724
    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 :/
     
unityunity