Search Unity

Native Share for Android & iOS [Open Source]

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

  1. semyoussef

    semyoussef

    Joined:
    Jan 30, 2018
    Posts:
    2
    I used the example code on the GitHub. I tried with Unity 2018.3.3f1, same thing. Any idea?

    EDIT : I've just ran 2 more tests on 2 different mobile phones (android 7.0 and android 5.1) and the image sharing worked just fine. Seems like the issue is related to my phone or maybe the android version 6.0.1.

    EDIT2 : The issue was definitively related to my phone! There was some problem with the sharing functionality on my phone. After some research on the internet, I fixed it. The asset works now like a charm :)
     
    Last edited: Feb 25, 2019
  2. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    663
    "Can't file ContentProvider, share not possible!"
    Problem gets solved by applying this suggestion.
     
  3. LevRiver1

    LevRiver1

    Joined:
    Nov 29, 2016
    Posts:
    1
    Thank you for the great asset. It's working great on my test devices.
    But i have an issue uploading the app via Xcode to the App Store.
    I get an error:
    ERROR ITMS-90432: Invalid Swift Support. The file ../NativeSahre.mm doesn't have the correct filetype for this location. Ensure you're useing the correct file......
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Is NativeSahre a typo you've made by mistake or is it what Xcode outputs?
     
  5. goodguy

    goodguy

    Joined:
    Jul 21, 2012
    Posts:
    18
    It doesn't work on ios for some reason. I thought the problem was in image storage path, but then I started using NativeGallery to save image to gallery. It saves the image just fine. Then I check the path to the image using the same plugin and then pass it to NativeShare.
    It works just fine on android but nothing happend on ios. Nothing at all. But the image is definitely there in the gallery
     
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Does File.Exists(imagePath) return true? If you use AddText and/or AddSubject, try removing them to see if it changes anyting.
     
  7. pedro_eloideias

    pedro_eloideias

    Joined:
    Feb 18, 2019
    Posts:
    7
    Any know issues for iOS? I can send the msg but the photo is missing.
     
  8. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    When sharing a photo with a text, some apps may omit the text or the photo, unfortunately. For best results, you are recommended to share the photo only (without text or subject).
     
  9. amateurhr

    amateurhr

    Joined:
    Jun 28, 2013
    Posts:
    6
    Accidentally created this message in your github repo when it should have gone in this forum!

    Yasirkula, we're finding that we're losing 90% of our shares because the users cancel when they get to the share sheet screen (the Apple UI just is too scary for some folks): https://screencast.com/t/FUPkyrq4u

    Question: Is there a way to skip that share sheet entirely and either bring up the text message composer?
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
  11. antonelli_f

    antonelli_f

    Joined:
    Oct 12, 2018
    Posts:
    3
    Hi yasirkula, nice to meet you! Here, Francisco from Argentina.
    Thank you VERY much for this plugin, i love it, its very simple ti use.

    I have some questions for you.
    1 - I'm using the same code from the example on github to share a texture from a screenshot. I can't get it work on iOS (i tested on an iPhoneX), the image is not appearing. When i select whatsapp, it only displays the shared text. When i use mail, appears the shared texth and a black image (it looks like the image could not be found). Do you have any clue?
    2 - I need to share an audioclip, ideally as mp3, do you know how can achieve this?

    Thank you again!
     
  12. antonelli_f

    antonelli_f

    Joined:
    Oct 12, 2018
    Posts:
    3
    Well, i could resolve the Black Screen on iOS when sharing an image.
    I found an error message on XCODE that says:

    Code (JavaScript):
    1. ReadPixels was called to read pixels from system frame buffer, while not inside drawing frame
    And that was because i was trying to take an screenshot outside a monobehaviour, outside a coroutine.

    I'm still without success sharing an audioclip as mp3.
     
  13. antonelli_f

    antonelli_f

    Joined:
    Oct 12, 2018
    Posts:
    3
    Hello again. For those who needs to share an audioclip, an my case an mp3, I found a way. You have to locate the file in the Streaming Assets folder (search in google how to do it). Once the file is there, they can do something like this:

    Code (CSharp):
    1.         private void Share(SoundClip clip)
    2.         {
    3.             var clipName = "clip001.mp3";
    4.             var filePath = Path.Combine(Application.streamingAssetsPath, clipName);
    5.             new NativeShare().AddFile(filePath).Share();
    6.         }
     
    yasirkula likes this.
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Thank you for the code snippet. You may also use some plugins to convert an AudioClip to an audio file (wav, mp3, etc.) and then share that file.

    WhatsApp on iOS may not support sharing an image with a text, so you should try omitting the text or the image from the shared content. If I were you, I'd omit the text, user can then fill the text themselves if he/she wants.
     
  15. bloodbc

    bloodbc

    Joined:
    May 9, 2013
    Posts:
    17
    Hello @yasirkula ,

    Thank you for the plugin, it's working like a charm! I just have one issue, with the email sharing on iOS, the application crash after sharing, with the following error on iPhone SE (not tested on other iOS devices yet):

    In Unity Player Settings I'm in Auto Rotation, with only Portrait as Allowed Orientations For Auto Rotation.

    I found some possible solutions on Stack, but I'm not used to native iOS code and some of them require to modify App Delegate or UIViewController... I don't get it! If you have any idea, thank you for your help!

    EDIT: I removed Auto Rotation and just set Portrait as the Default Orientation. It's working for my app but I guess some people may need another solution to let Auto Rotation enabled.
    You can check within UnityAppController.mm, look for supportedInterfaceOrientationsForWindow, there you can try to always return UIInterfaceOrientationMaskAll. However there is a comment from Unity about that:
     
    Last edited: Mar 18, 2019
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Glad you could resolve the issue! Indeed, it looks like a serious issue but I would prefer not fiddle with things like UnityAppController.mm because a) Unity could change its contents over time and b) it might yield unwanted results as you suggested. So there isn't a bugfix for this issue at the moment, unfortunately.
     
  17. gunner-ayz

    gunner-ayz

    Joined:
    Jul 30, 2018
    Posts:
    2
    Hi. Used your plugin and absolutely loved it. Awesome word.

    I just need a little guidance: For sharing with multiple contacts, is there a way to return count on selected contacts?

    for instance let's say the user shares the link to 5 people to get the reward. can the app return the count of selected contacts on unity?
     
    Last edited: Mar 27, 2019
  18. dddon

    dddon

    Joined:
    Jan 3, 2014
    Posts:
    6
    Hello, i want to ask how can I use:
    NativeGallery.GetImageFromGallery
    to get selected image path (filePath)

    And then share selected one by:
    new NativeShare().AddFile(filePath).SetSubject("Subject goes here").SetText("Hello world!").Share();
    ?

    Is it even possible?
     
  19. dddon

    dddon

    Joined:
    Jan 3, 2014
    Posts:
    6
    Never mind...
    Code (CSharp):
    1.     private void PickImage(int maxSize)
    2.     {
    3.         NativeGallery.Permission permission = NativeGallery.GetImageFromGallery((path) =>
    4.         {
    5.             Debug.Log("Image path: " + path);
    6.             if (path != null)
    7.             {
    8.                 // Create Texture from selected image
    9.                 Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize);
    10.                 if (texture == null)
    11.                 {
    12.                     Debug.Log("Couldn't load texture from " + path);
    13.                     return;
    14.                 }
    15.                 new NativeShare().AddFile(path).SetSubject("Subject goes here").SetText("Hello world!").Share();
    16.  
    17.             }
    18.         }, "Select a PNG image", "image/png", maxSize);
    19.  
    20.         Debug.Log("Permission result: " + permission);
    21.     }
    Seems to work after i added Android Manifest correctly. Path stops to get null value. Great plugins! Thank you so much
     
    yasirkula likes this.
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
  21. shlighter

    shlighter

    Joined:
    Mar 2, 2017
    Posts:
    40
    Hey there, just updated the plugin to 1.5.7, and Unity to 2018.3.9f1, I get the same error (as the other user here)- Unfortunately, Android system has stopped. The plugin used to work perfectly on my Android phone, and now after all the updates it fails when I try to share my texture.
     
    Last edited: Mar 28, 2019
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
  23. gunner-ayz

    gunner-ayz

    Joined:
    Jul 30, 2018
    Posts:
    2
    @yasirkula one more thing i wanted to ask: is there a way to return the medium of sharing. e.g if user clicks on whatsapp, we may know that he has chosen whatsapp as the sharing medium. Regards
     
  24. Renato_Rewind

    Renato_Rewind

    Joined:
    Mar 7, 2019
    Posts:
    3
    We are using this plugin as a base for sharing. Currently we only target twitter, with either screenshot or text. Everything works fine for the text, but after sharing a screenshot twitter seem to lock down. Unsure what it is, I'm investigating.
    Do you have any guess?
    I'm sharing a screen capture from a saved file. The first time everything is fine, but then any other share ( even text ) get the following popup:
    "All apps associated with this action have been turned off, blocked, or are not installed"

    Thank you for this cool, free tool.
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    @gunner-ayz NativeShare doesn't support any kind of callback, sorry.

    @Renato_Rewind Have you used any Package disabler apps? Is this issue persistent across different devices/emulators?
     
  26. Renato_Rewind

    Renato_Rewind

    Joined:
    Mar 7, 2019
    Posts:
    3
    the issue is persistent on across about 3/4 devices we tested. I don't think is about a disabler app ( but will double check ) because it tend to work with text. The screenshot on the other end break it after the first share.

    The code I use is the following:
    Code (CSharp):
    1.  
    2.                 NativeShare.AddFile(fullFileName, "image/png").SetTarget(TwitterPackageName).Share();
    As stated, it works perfectly the first time, but then the app get blocked. Worth noting on these devices we use always the same twitter account.
     
  27. Renato_Rewind

    Renato_Rewind

    Joined:
    Mar 7, 2019
    Posts:
    3
    @yasirkula I fixed it. My bad. My stupidity work wonders sometimes: I always set the target to twitter and never tried other targets. If you add multiple png files to twitter and tweet, for some reason it locks the app from tweeting. Using only one file at at time fixed it.
     
    yasirkula likes this.
  28. leekinon

    leekinon

    Joined:
    Dec 4, 2013
    Posts:
    21
    螢幕快照 2019-04-03 下午10.17.04.png
    Code (Boo):
    1. UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
    2.   at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00234] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:190
    3.   at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x0007f] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPlayerWindowBuildMethods.cs:96
    4. UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    Code (Boo):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <manifest
    3.     xmlns:android="http://schemas.android.com/apk/res/android"
    4.     package="com.unity3d.player"
    5.     xmlns:tools="http://schemas.android.com/tools"
    6.     android:installLocation="preferExternal">
    7.     <supports-screens
    8.         android:smallScreens="true"
    9.         android:normalScreens="true"
    10.         android:largeScreens="true"
    11.         android:xlargeScreens="true"
    12.         android:anyDensity="true"/>
    13.      
    14.  
    15.     <application
    16.         android:theme="@style/UnityThemeSelector"
    17.         android:icon="@mipmap/app_icon"
    18.         android:label="@string/app_name">
    19.         <activity android:name="com.unity3d.player.UnityPlayerActivity"
    20.                   android:label="@string/app_name">
    21.             <intent-filter>
    22.                 <action android:name="android.intent.action.MAIN" />
    23.                 <category android:name="android.intent.category.LAUNCHER" />
    24.             </intent-filter>
    25.             <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    26.         <provider
    27.         android:name="com.unity.project"
    28.         android:authorities="keyasdfgh123"
    29.         android:exported="false"
    30.         android:grantUriPermissions="true" />
    31.         </activity>
    32.     </application>
    33. </manifest>


    build fail after install this asset
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Does this happen when you add the plugin to a fresh new project and try to build it? What happens when you disable Minification under Player Settings?

    P.S. Nevermind, you must leave android:name as "com.yasirkula.unity.UnitySSContentProvider" and I think that's the issue.
     
  30. bobeogames

    bobeogames

    Joined:
    Feb 9, 2019
    Posts:
    8
    Hi Yasirkula,

    I'm using your plugin and it works fine except one thing, the text I use in SetText() does not appear in sharing post facebook. I think it should be that or am I wrong?

    Note: I tried sharing via Mail, Zalo, the text displayed. I would like to add a text to share address of my game in google play.
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Facebook doesn't support sharing an image with a text without using Facebook SDK. This plugin doesn't use any social platform SDKs like Facebook or Twitter, so you can share either text or image on Facebook.
     
    bobeogames likes this.
  32. unity_gJ8wt_N_jkroyg

    unity_gJ8wt_N_jkroyg

    Joined:
    Apr 11, 2019
    Posts:
    2
    Congratulations for the pluggin, my problem is when it comes to sharing audio, I have no problem sharing images and captures.

    This is the part of the code that fails me.
    AudioClip audio = Resources.Load ("audio", typeof (AudioClip)) as AudioClip;
    yield return null;

    string filePath = Path.Combine (Application.temporaryCachePath, "Shared img.png");

    File.WriteAllBytes (filePath, audio.//**********);

    where an EncodePNG should be, I do not know how to compress it if it's an audio.
    thank you
     
  33. unity_gJ8wt_N_jkroyg

    unity_gJ8wt_N_jkroyg

    Joined:
    Apr 11, 2019
    Posts:
    2
    Cant understand "SoundClip"
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
  35. levilais

    levilais

    Joined:
    Jul 19, 2018
    Posts:
    3
    2 Questions - 1) do you have a completion handler that we can access the moment the user returns from share. 2) do you have the ability to set the "to" field (ie email in Mail and phone number in Messages)?
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
  37. GamerSuji

    GamerSuji

    Joined:
    Aug 1, 2015
    Posts:
    5
    Hi yasirkula, I thoroughly enjoy working with your plugin. The android build are working flawlessly but the iOS builds give me this error when i share the screen shot "Unable to send item - Please try again later (401)". Also when i started the build on my iPad It did not ask for any sort of storage permission which is pretty odd because I tried the method b which was put in the github page. I added a new photo library usage description yet still I get that error. Kindly help me out with this one.
     
  38. UKRLOGIC

    UKRLOGIC

    Joined:
    Sep 29, 2016
    Posts:
    1
    I have a non-standard error. everything works fine on ios, but nothing works on android after pressing the button. upd. no image works
     
    Last edited: Apr 22, 2019
  39. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    @GamerSuji Thank you. Strangely, when I google "Unable to send item - Please try again later (401)", I find no results. I'm not sure why this happens. If this issue is not persistent on other shareable apps, then it can be an app-specific issue.

    @UKRLOGIC Did you update your AndroidManifest? If so, try omitting the SetText and SetSubject functions from your code.
     
  40. lucks17

    lucks17

    Joined:
    Jan 20, 2014
    Posts:
    9
    Hi, I tested the source code on Android and works perfect with Unity 2019, but on iOS, when I compile and test a share button, the image is not sending, on the preview I see it, but not is sent. I got the following error on Xcode:
    2019-04-25 16:35:06.293911-0500 test[603:128314] [core] SLRemoteComposeViewController: (this may be harmless) viewServiceDidTerminateWithError: Error Domain=_UIViewServiceErrorDomain Code=1 "(null)" UserInfo={Terminated=disconnect method}
     
  41. lucks17

    lucks17

    Joined:
    Jan 20, 2014
    Posts:
    9
    If only image is sendin on iOS, work just with the image shared, but if you need text and image, don't work :(
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Sharing an image with a text can be problematic for other applications, as well. I don't know why some applications decide to omit the text or the image but for the best result, you should share either only text or only image.
     
  43. chemdroid2018

    chemdroid2018

    Joined:
    Mar 3, 2019
    Posts:
    1
    First Thanks for the plug-in, huge help. QUESTION how come it only allows me to share on facebook it doesnt allow me to choose what app can i share the app. Is it also possible to send it as a message to facebook messenger instead of a timeline post?
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    Are you using the SetTarget function?
     
  45. rakshithjuego

    rakshithjuego

    Joined:
    May 13, 2019
    Posts:
    1
  46. HarshZvky

    HarshZvky

    Joined:
    May 13, 2019
    Posts:
    1
    Hello @yasirkula , thanks for this plugin. It has been really helpful. I have some questions regarding this:

    I see that in your example code, that we can limit the share function to only Whatsapp. How can we do the same for only Facebook or only Instagram? And is this possible in iOS as well?

    Next, you have mentioned that posting text along with the picture is not possible in Facebook. Is this only in iOS or both Android and iOS?

    Thanks!
     
  47. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    @rakshithjuego Might be a limitation of the Facebook app (similar to how you can't share an image with a text). Please see: https://stackoverflow.com/a/14496338/2373034

    @HarshZvky If you know the name of the Facebook share activity (or plan to use NativeShare.FindTarget to find the activity's name), then you can share on Facebook only, yes. Same goes for any application. This feature is not supported on iOS.

    I haven't tested sharing an image with a text on Facebook on iOS but I don't it will work on that platform either :/
     
    HarshZvky likes this.
  48. cses

    cses

    Joined:
    May 3, 2019
    Posts:
    1
    HI @yasirkula
    I use SetText is OK, but AddFile show log "Can't find ContentProvider, share not possible!"
     
  49. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    925
    It occurs when the <provider> is not set up correctly in AndroidManifest. See README.txt if you haven't modified your AndroidManifest at all, or please paste it here so I can see its contents. Also make sure that your AndroidManifest is located exactly at Assets/Plugins/Android/AndroidManifest.xml.
     
  50. Andreas_StrangeQuest

    Andreas_StrangeQuest

    Joined:
    Mar 12, 2019
    Posts:
    5
    Hi yasirkula and thank you for an awesome and easy to use asset.
    I do have a problem though with file sharing.
    I do know that I have a file at the correct path (even tried your simple example) but every time I use .AddFile(filePath) the sharing is just not doing anything. No native screen is popping up and it just silently does nothing.
    Sharing all the texts works just fine and as intended. I have tried empty png, screenshot or written a file from resources down to temp cache. Nothing at all.
    I also tried not setting subject nor text. Still no native dialogue even starts.
    Have I missed something in the manifest that allows text but not files???
     
    Last edited: Jun 5, 2019