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. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You must delete the provider tag from AndroidManifest.
     
  2. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    I have deleted provider tag and your plugin. After that, I have imported it again, but it still have error :(
     
  3. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please make sure that there are no providers with name "com.yasirkula.unity.UnitySSContentProvider" in any of your AndroidManifest files. NativeShare doesn't use that class anymore so it isn't added by NativeShare. As a last resort, you can also delete your Library folder and see if it helps.
     
    dan_ginovker likes this.
  4. nbkhanhdhgd

    nbkhanhdhgd

    Joined:
    Apr 19, 2016
    Posts:
    23
    Thank you so much!!!!
    It worked ;)
     
    yasirkula likes this.
  5. MaryamKamel

    MaryamKamel

    Joined:
    Feb 5, 2016
    Posts:
    22
    hello @yasirkula ,
    thanks for your work and thanks for sharing these great plugins with us,
    i am saving an image using NativeGallery and i used the GetTemporarySavePath to get the path and use it for sharing but i get the following error on logcat,
    E/Unity: File does not exist at path or permission denied: /storage/emulated/0/Android/data/com.Linkdev.IHFARApp/files/NGallery/IMG03-06-2020-16-20-21.jpg
    NativeShare:AddFile(String, String)

    i am only sharing and image right now without a text,
    any hints?
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    NativeGallery doesn't support retrieving the saved image's path, so you shouldn't rely on GetTemporarySavePath. You can save a copy of the image to Application.temporaryCachePath and use that path instead.
     
  7. MaryamKamel

    MaryamKamel

    Joined:
    Feb 5, 2016
    Posts:
    22
    @yasirkula ,
    i went through this forum's posts and :oops: saw a post about sharing a video saved by nativegallery and GetTemporarySavePath was suggested, so i thought it already does that,
    now that you highlighted the difference i saved it in the cache and its working perfectly :D thanks for the swift reply ,
    and keep up the good work (y) ;).
     
    yasirkula likes this.
  8. DBarbara

    DBarbara

    Joined:
    Oct 24, 2018
    Posts:
    3
    Hello,

    I'm getting a serious issue while trying to share on Messenger on some iOS devices.

    Messenger changed the share interaction to give the user some waiting time so they can cancel the share action before it is done. While on Android the wait is okay, on some iOS devices it simply doesn't wait and closes the native prompt for sharing, cancelling the action. Resulting in never being able to share over Messenger. We only share links, using the SetText.



    Is this fixable? Overall this plugin works just fine and suits all of our current and future needs, I really wouldn't like to change.
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I tried googling this canceling feature in a number of ways like "messenger cancel share" or "messenger adds cancel share feature" but couldn't see any posts about the feature. I was then planning to search technical topics on stackoverflow but now I don't know what keywords to use to find relevant results.
     
  10. DBarbara

    DBarbara

    Joined:
    Oct 24, 2018
    Posts:
    3
    It's not exactly a feature but a minor UX change. If you try to share using facebook you will notice how it seems. 2-3 secs of showing "Undo" before graying out and showing "Sent"
     
  11. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  12. DBarbara

    DBarbara

    Joined:
    Oct 24, 2018
    Posts:
    3
    Thanks for the help.

    The exact cause, why it behaves like this with that URL still a mystery but at least we can work around.

    After a lot of testing we found out what was the issue, our QA misled us to think it was something with the plugin and this behaviour of the Messenger app.We found out it was the URL we were sharing. It had some issues on sharing through messenger on iOS, for some reason being shortened by a service from Amazon made it unshareable in that environment. We tried setting subject, other kinds of text, etc until we found out that we use another third-party shortener it would work.

    Again, thanks for the help.
     
    yasirkula likes this.
  13. novaVision

    novaVision

    Joined:
    Nov 9, 2014
    Posts:
    518
    Is there any way to get share dialog close callback? (cancelled or shared successfully)? The problem is that game not pause and app is still in foreground, and there is no event to listen to resume the gameplay.
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    NativeShare doesn't support callbacks, sorry.
     
  15. AtillaTheDev

    AtillaTheDev

    Joined:
    Apr 30, 2020
    Posts:
    10
    Hello,
    Thanks for this great package.
    I imported the package via assetstore and it is now in assets->plugins folder but in Visual Studio, in solution of the project that I imported the package, I cannot access the NativeShare class?

    Am I missing something?
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Replied to your other comment.
     
  17. black_caleb

    black_caleb

    Joined:
    Sep 13, 2019
    Posts:
    3
    Hello,
    My app, working for android and for IOs, is using the plugin to simply share a screenshot.
    On android everything is working fine, but on IOs there is an issue with sharing via third party applications.
    Although they are visible in the selection of the apps they are not able to share the screenshot.

    From the Log:
    [26427:6246222] [lifecycle ] [u F644722D-2BEF-47BA-860C-FD94A247EDD1:m (null)] [com.hammerandchisel.discord.Share(28.0)] Connection to plugin interrupted while in use. and
    [com.hammerandchisel.discord.Share(28.0)] Connection to plugin invalidated while in use.
    [26427:6245354] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
    [26427:6245354] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted}
    [26427:6245354] Warning: Attempt to dismiss from view controller <UIActivityViewController: 0x13623d400> while a presentation or dismiss is in progress!
    [26427:6245549] [lifecycle ] [u A14D42C2-952F-4D79-B7D5-2828E657F09D:m (null)] [com.apple.share.Facebook.post(274.0)] Connection to plugin interrupted while in use.
    [com.apple.share.Facebook.post(274.0)] Connection to plugin invalidated while in use.
    [26427:6245354] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
    [26427:6246787] [lifecycle ] [u 84E14A41-9A75-43C3-8729-19D5F535D708:m (null)] [net.whatsapp.WhatsApp.ShareExtension(2.20.61)] Connection to plugin interrupted while in use.
    [26427:6245354] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
    [26427:6246787] [assertion] Error acquiring assertion: <NSError: 0x28313ea00; domain: RBSAssertionErrorDomain; code: 2; reason: "Specified target process does not exist">
    [26427:6246709] [lifecycle ] [u F644722D-2BEF-47BA-860C-FD94A247EDD1:m (null)] [com.hammerandchisel.discord.Share(28.0)] Connection to plugin interrupted while in use.
    [com.hammerandchisel.discord.Share(28.0)] Connection to plugin invalidated while in use.
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Are you trying to share a screenshot with text? What happens when you don't call SetText and SetSubject functions?
     
  19. black_caleb

    black_caleb

    Joined:
    Sep 13, 2019
    Posts:
    3
    No i am not using a text. Here the function which make use of the plugin.
    I looked to keep it as simple as possible.

    private void ShareTexture(Texture2D TextureToSave)
    {
    var bytes = TextureToSave.EncodeToPNG();
    var path = Config.PersistantCacheUrl + "/tmp.png";
    File.WriteAllBytes(path, bytes);
    NativeShare sharehandle = new NativeShare();
    sharehandle.AddFile(path);
    sharehandle.Share();
    }
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I can see the error messages "Connection to plugin invalidated while in use" and "Connection to plugin interrupted while in use" for Discord, Facebook and WhatsApp. Since you didn't tell that "only Discord has this problem", I'm assuming that sharing doesn't work for any of these apps.

    Googling these issues didn't yield any useful results, so I can't tell why this is happening at the moment. I'd recommend you to create a new Unity project, import Native Share and test the example code on an actual iOS device (not Simulator). If it works, then the issue is related to either the path in your code or something else in your own project.
     
    black_caleb likes this.
  21. black_caleb

    black_caleb

    Joined:
    Sep 13, 2019
    Posts:
    3
    The issue happens only with third party applications.

    I will try that out. Thanks for the quick answer.
     
  22. AtillaTheDev

    AtillaTheDev

    Joined:
    Apr 30, 2020
    Posts:
    10
    Yes, got it.
    Thank you so much.
    Everything is fine about the package.
     
  23. qinxinyu

    qinxinyu

    Joined:
    Jul 10, 2020
    Posts:
    1
    very very nice.best wishes!
     
    yasirkula likes this.
  24. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Added share callback support with the latest release! It was undoubtedly the most requested feature. Already available on GitHub. Asset Store version is pending review.
     
    AtillaTheDev likes this.
  25. mobilelearning

    mobilelearning

    Joined:
    Mar 28, 2017
    Posts:
    3
    Hello sir,
    I'm using the project https://github.com/thanh-nguyen-kim/Unity_Android_Screen_Recorder
    there i got the line (+NativeShare for native send or share a video, image or text via social network). in that project it can record & save video to gallery. but i want one more button for sharing video. I'm very new on unity.,i know its easy for experienced developer to crate share option for recorded video, but for me only specific details or example scene works. please help me to do so with your plugin.
     
  26. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I don't think that the author meant to mention my plugin when he said NativeShare, they meant their own native sharing function(s). I don't know how you can use their functions. If you want to use my NativeShare plugin, you can check out the documentation and example code at: https://github.com/yasirkula/UnityNativeShare#example-code
     
  27. melvard

    melvard

    Joined:
    Jun 23, 2018
    Posts:
    5
    Yasirkula, thank you for native share plugin.
    Now I am using latest version of this plugin and as I can see in GitHub I don't have to make any manual changes in AndroidManifest.xml. Now when I build my project as not gradle project it works perfectly (screenshot attached), but when I build gradle project share function does not work (share panel does not show up) upload_2020-7-25_17-9-11.png
     
    Starpaq2 likes this.
  28. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Can you check logcat logs and see if a NativeShare-related error message is logged there when you attempt to share?
     
  29. melvard

    melvard

    Joined:
    Jun 23, 2018
    Posts:
    5
    I am using BlueStacks to test apk-s and can't find way to check the logs. But I have same problem with 2 other Anrdoid devices(problem is not with emulator).
     
  30. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Can you check logcat on those other devices? Knowing the error messages really help debugging the issue.
     
  31. melvard

    melvard

    Joined:
    Jun 23, 2018
    Posts:
    5
    I replaced datelog with "-------------------- ".
    So you were right, here is an "E" (Error)


    -------------------- 3754 3810 E Unity : AndroidJavaException: java.lang.ClassNotFoundException: com.yasirkula.unity.NativeShare
    -------------------- 3754 3810 E Unity : java.lang.ClassNotFoundException: com.yasirkula.unity.NativeShare
    -------------------- 3754 3810 E Unity : at java.lang.Class.classForName(Native Method)
    -------------------- 3754 3810 E Unity : at java.lang.Class.forName(Class.java:400)
    -------------------- 3754 3810 E Unity : at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
    -------------------- 3754 3810 E Unity : at com.unity3d.player.UnityPlayer.access$300()
    -------------------- 3754 3810 E Unity : at com.unity3d.player.UnityPlayer$e$1.handleMessage()
    -------------------- 3754 3810 E Unity : at android.os.Handler.dispatchMessage(Handler.java:98)
    -------------------- 3754 3810 E Unity : at android.os.Looper.loop(Looper.java:154)
    -------------------- 3754 3810 E Unity : at com.unity3d.player.UnityPlayer$e.run()
    -------------------- 3754 3810 E Unity : Caused by: java.lang.ClassNotFoundException: Didn't find class "com.yasirkula.unity.NativeShare" on path: DexPathList[[zip file "/data/app/com.takear.takear-1/base.apk"],nativeLibraryDirectories=[/data/app/com.takear.takear-1/lib/arm, /data/app/com.takear.takear-1/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib, /data/downloads, /data/priv-downloads]]


    -------------------- 3754 3810 E Unity : at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    -------------------- 3754 3810 E Unity : at java.lang.ClassLoader.loadClass
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Seems like NativeShare classes are stripped from your build but I'm not sure why. I can see that you have Minification disabled, which is good. Are you building the game from Android Studio or did any other plugins you are using mention in their documentation that they activate e.g. ProGuard while building the game?
     
    melvard likes this.
  33. melvard

    melvard

    Joined:
    Jun 23, 2018
    Posts:
    5
    Auuuu, Thank you very much.
    Worked super!
    I am using Unity Editor while building and have selected custom ProGuard option checkbox, so I had build error when unchecked that option, as mainTemplate.gradle used it. So I added

    -keep class com.yasirkula.unity.* { *; }


    to my "proguard-user.txt" and it worked perfectly!

    Thank you!
     
    Starpaq2 and yasirkula like this.
  34. DJgray3D

    DJgray3D

    Joined:
    Mar 6, 2013
    Posts:
    15
    Hi, great plugin!

    I was wondering if you could help me with an issue I'm having with iOS.
    I have one button that takes a screenshot and saves it to the PersistentDataPath, then another button that shares the screenshot (this is your plugin).
    I've tried with and without the text but I get the same error in Xcode:

    Code (CSharp):
    1. Share Error: file does not exist at path or permission denied:
    When I save the take the screenshot, my log tells me that it's saved to:

    Code (CSharp):
    1. /var/mobile/Containers/Data?Application/644A65F2-8BF9-4311-AFB3-1195A446EEDD/Documents/MyScreenshot_02-33-27_12-08-20.jpg
    But when I try to get the image from the PersistentDataPath to share, the log comes up with no pathway

    Any ideas?
     
  35. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Unity's screen capture functions may not save the screenshot to the target path immediately. The "Share Error" only occurs when File.Exists returns false, so the image doesn't exist at that path when you call NativeShare.AddFile. The example code also has a screenshot function, you can try using that instead: https://github.com/yasirkula/UnityNativeShare#example-code
     
    DJgray3D likes this.
  36. tmulla

    tmulla

    Joined:
    Jan 16, 2020
    Posts:
    8
    @yasirkula , thanks for the plugin mate, its light and works great. but I've an issue with keyboard while sharing an image on iOS instagram, its not opening keyboard if I want to add text before sharing my image. key works for other sharable apps for ex: FB and whatsapp. Do you why this issue?
     
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    I'd like to believe that this issue isn't caused by NativeShare because it has no app-specific logic in it.
     
  38. pravin_hashbyte

    pravin_hashbyte

    Joined:
    Aug 24, 2019
    Posts:
    1
    @yasirkula its opening panel of apps to which you can share, but when try to open whatsapp , it shows toast message "Cant send empty message" and app get stuck... please provide solution.
     
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    May I see your sharing code?
     
  40. JakeJC

    JakeJC

    Joined:
    Nov 2, 2016
    Posts:
    2
    @yasirkula hi I just wanted to ask if it is possible to show only some apps in the share pannel? I want to have a button for Instagram and then button for facebook and no other apps...
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Please check out the relevant FAQ entry here.
     
  42. tmulla

    tmulla

    Joined:
    Jan 16, 2020
    Posts:
    8
    @yasirkula Hi, Is there a way to exclude specific apps from showing up on native share UI, say I don;t want FB app or instagram app to show up and show all the other apps that are installed?
     
  43. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  44. Onichan410

    Onichan410

    Joined:
    Jan 13, 2018
    Posts:
    2
    @yasirkula Hi. Thanks for you package. I got some troubles with saving photos in IOS Photo Gallery. Error in console Share error: Error Domain=ALAssetsLibraryErrorDomain Code=-3310 "Data unavailable" UserInfo={NSUnderlyingError=0x2805c0cf0 {Error Domain=ALAssetsLibraryErrorDomain Code=-3310 "Data unavailable" UserInfo={NSUnderlyingError=0x28043e970 {Error Domain=com.apple.photos.error Code=-3001 "(null)"}, NSLocalizedDescription=Data unavailable, NSLocalizedRecoverySuggestion=Launch the Photos application}}, NSLocalizedDescription=Data unavailable, NSLocalizedRecoverySuggestion=Launch the Photos application
    Please, help me
     
  45. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    You are using NativeShare, NOT NativeGallery; am I right? If so, on which iOS version are you having this issue? Does uninstalling and then reinstalling the app help?
     
  46. Onichan410

    Onichan410

    Joined:
    Jan 13, 2018
    Posts:
    2
    Yes, you are right. I'm using iPad 2020 pro with iOS 13.6.1. Reinstalling app doesn't help for me. I write all permission as guideline Photo Library Usage and Photo Additional Usage.
     

    Attached Files:

  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
  48. Andelusiy

    Andelusiy

    Joined:
    Mar 24, 2020
    Posts:
    4
    @yasirkula Hi, I just wanted to use Native Share< downloaded, imported it in my project, wrote a script and then tried to build my app , got some error, could u help me please:(
    upload_2020-9-9_22-46-26.png
     
  49. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    2,879
    Are you sure that this is caused by NativeShare? I'd recommend you to close your Unity project, delete the Library folder, delete first.apk file, reopen the Unity project and build again.
     
  50. Andelusiy

    Andelusiy

    Joined:
    Mar 24, 2020
    Posts:
    4
    Now it WORKS!!! Thank you so much!
     
    yasirkula likes this.
Thread Status:
Not open for further replies.