Search Unity

Native Share for Android & iOS [Open Source]

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

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Can you use Logcat to see if there are any meaningful error messages that pop up when you call the Share() function?
     
  2. Andreas_StrangeQuest

    Andreas_StrangeQuest

    Joined:
    Mar 12, 2019
    Posts:
    5
    Unfortunately not much except for Unity exceptions and the previous posters error message:

    06-05 10:48:15.869 com.strangequest.gogogrenade 2690 2735 I Unity File path: /storage/emulated/0/Android/data/com.strangequest.gogogrenade/cache/shared_img.png
    06-05 10:48:15.869 com.strangequest.gogogrenade 2690 2735 I Unity UnityEngine.DebugLogHandler:Internal_Log(LogType, LogOption, String, Object)
    06-05 10:48:15.869 com.strangequest.gogogrenade 2690 2735 I Unity UnityEngine.DebugLogHandler:LogFormat(LogType, Object, String, Object[])
    ...
    ...
    06-05 10:48:15.871 com.strangequest.gogogrenade 2690 2735 D Unity > ExceptionOccurred()
    06-05 10:48:15.871 com.strangequest.gogogrenade 2690 2735 D Unity > CallStaticVoidMethod(0x3d2a, 0xe5986f1c
    06-05 10:48:15.872 com.strangequest.gogogrenade 2690 2735 E Unity Can't find ContentProvider, share not possible!
    06-05 10:48:15.872 com.strangequest.gogogrenade 2690 2735 D Unity > ExceptionOccurred()

    EDIT: With yasirkula's guidance I found out that even though properly added provider in the manifest it seems like Unity didn't added it to the final build. Be it a cacheproblem or weirder (I had to move the provider line a bit up, not being in the bottom in the <application> tag). It now works and file sharing is as expected!
     
    Last edited: Jun 5, 2019
  3. sajjadgrw1

    sajjadgrw1

    Joined:
    Apr 12, 2019
    Posts:
    1
    I did not tried plugin to load resources from library and obviously screenshot share as mentioned in plugin example is working perfectly fine. I do have a short 10 sec video mp4 format in Assets folder and trying to share it. But there is always following error message
    File do not exist or you dont have permission
    I have access to video clip object and its original path is returning same error even did tried with file:// prefix and moving video to resources folder as well but no luck
    I read about saving and reading files from persistentdatapath. Is this the only way to do it ? Or am i doing something wrong ?
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    If
    File.Exists(filePath)
    returns false, then NativeShare can't share that file. Be aware that assets in your project are packed together while building your project, so even though every asset is a separate file in your Unity project, it is no longer the case in a built game.

    If you want, you can import the video as TextAsset in your project and at runtime, save it to a temporary location in order to share it:

    Code (CSharp):
    1. public TextAsset video;
    2.  
    3. public void ShareVideo()
    4. {
    5.     string path = System.IO.Path.Combine( Application.temporaryCachePath, "video.mp4" );
    6.     System.IO.File.WriteAllBytes( path, video.bytes );
    7.  
    8.     new NativeShare().AddFile( path ).Share();
    9. }
    To import a video as TextAsset, you need to change its extension from
    .mp4
    to
    .bytes
    .
     
  5. AlonsOh

    AlonsOh

    Joined:
    Jan 11, 2017
    Posts:
    6
    Hello @yasirkula great plug in thanks a lot! It works wonders sharing my local pdf file, but was wondering is there a way to launch a direct file download ? and prevent selecting from multiple possible apps ?
     
  6. Lad-Ty

    Lad-Ty

    Joined:
    May 7, 2013
    Posts:
    25
    Hi, first and foremost, thank you very much for putting your work out like this, extremely appreciated, seriously!
    I'm looking around for some basic sharing from our game and this looks great. Would like to ask though, will this bring up some additional permissions or stuff like that? If so, since I want to share only a text (+link), can it be avoided?
    I've read the readme, and it talks about info.plist stuff for iOS for example. The code in "NSPostProcessBuild.cs" seems to me though, that it is only required for accessing files on the device. Would it be OK if I just set "ENABLED" to false, as long as I only call "new NativeShare().SetSubject(subject).SetText(text).Share();" ?
    Is Android somehow affected by any file access permissions? Thank you
     
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    @AlonsOh To prompt a download, I'd recommend you to use Unity's Application.OpenURL function with the download link of the file. Please let me know if I understood you wrong.

    @Lad-Ty No additional permissions on Android. The PHOTO_LIBRARY_USAGE_DESCRIPTION on iOS is required when user selects the option to save the shared image/video to the Photos. In your case, as you are not sharing a file, that may not be necessary but there is no harm in keeping ENABLED as true.
     
  8. Lad-Ty

    Lad-Ty

    Joined:
    May 7, 2013
    Posts:
    25
    Thanks! I'm not that well versed with iOS overall, so I guess the usage description pops out only after the app is actually trying to do something with the file system, and until then, it is ok that the info.plist contains these fields added by the NSPostProcessBuild since they won't be used in my case?
    If so I'll keep enabled true, just so I don't forget it in case we were adding that functionality in the future or something :)
     
  9. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Yes, it won't pop up unless user selects the "Save to Photos" option in the share dialog.
     
  10. AlonsOh

    AlonsOh

    Joined:
    Jan 11, 2017
    Posts:
    6
    @yasirkula ah yes, I've tried that, it doesn't work on android apparently, I read that it requires you to put the file in the some kind of persistent data path in order for the openURL to work, but still it doesn't :\ actually, haven't tried putting the file in the temporary cache just like I do to share with your plugin, maybe that'll do the trick, I'll give it a try and let you know, thank you xD
     
  11. AlonsOh

    AlonsOh

    Joined:
    Jan 11, 2017
    Posts:
    6
    Nope, it didn't launch with openURL, I'll keep looking for workarounds, the file was put in `/storage/emulated/0/Android/data/com.mycompany.mypackage/cache/myFile.pdf` but the openURL didn't launched (no error or any other was notified through logcat)
     
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    I see. NativeShare isn't meant to be used as a download interface but it is possible to filter the list of applications in the share dialog via NativeShare's SetTarget function on Android. It is not possible on iOS.
     
  13. AlonsOh

    AlonsOh

    Joined:
    Jan 11, 2017
    Posts:
    6
    Oh, right, I tried that too, but failed selecting the right package XD, I tried to set it to com.google.android.apps.nbu.files but it said at runtime that no app can support that, I tried with the google chrome app package too (com.google.chrome I believe) and the same thing XD
     
  14. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    AlonsOh likes this.
  15. aporier

    aporier

    Joined:
    Jun 15, 2016
    Posts:
    5
    In my app, I take a screenshot, save it to the persistent data path, and from there I want to share the photo. Can I do that with this plugin?
     
  16. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Yes, you can use
    new NativeShare().AddFile(imagePath).Share();
    .
     
  17. flatsplay

    flatsplay

    Joined:
    Feb 6, 2019
    Posts:
    2
    Hello yasirkula. Thanks for a great plugin, it is very simple in use and works well. But I had one problem: as I know, facebook can share only image or text, not both of them at time. When I try to share image and text, Facebook attaches image. How can I change priority to text? (using only text when it is not complex sharing and text with image normally)
     
  18. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    I hear you but unfortunately there is no way to specify shared content per-app at the moment :/
     
  19. Skibitsky

    Skibitsky

    Joined:
    Mar 22, 2016
    Posts:
    1
    Hi,

    Have you tested it on iOS13? When we try to share image or text Activity View Controller freezes and status bar starts blinking. The same code works well on iOS12 and Android.
     
  20. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    That's new. I believe that'll be hard to debug, native-side issues like this usually don't provide any useful logs, especially now considering that it works well on iOS12.
     
  21. BloodyBeard

    BloodyBeard

    Joined:
    Oct 17, 2017
    Posts:
    4
    Hi @yasirkula . Thanks for good plugin. But I have an issue. Here's code:

    Code (CSharp):
    1. public Texture2D textureForSharing;
    2.  
    3.  
    4. private IEnumerator TakeSSAndShare()
    5. {
    6.         yield return new WaitForEndOfFrame();
    7.         string filePath = Path.Combine(Application.temporaryCachePath, "shared_img.png");
    8.         File.WriteAllBytes(filePath, textureForSharing.EncodeToPNG());
    9.  
    10.         new NativeShare().AddFile(filePath).Share();
    11. }
    So it's work perfect at Dev build, but doesn't work at all at Release build.

    Unity 2018.3.9f1
    Android 8.1(Nexus 5X) - 9 (Samsung A30)

    Any ideas, please?
     
  22. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    BloodyBeard likes this.
  23. MrKmproductions

    MrKmproductions

    Joined:
    Nov 11, 2016
    Posts:
    1
    Heyo! Having a small issue with NativeShare that I was hoping you could help me with. For my program, I am trying to email a directory with all of the subdirectories attached. The folder I'm hoping to send is entitled Information, which has other folders within it, with additional files within those folders.

    Here's my code so far; when I share it, the subject pops up but the body doesn't have the folder attached:
    Code (CSharp):
    1. public void exportAllDataButton() {
    2.  
    3.         new NativeShare().AddFile(Application.persistentDataPath + "/Information/").SetSubject("Export From: " + timeText.text).SetTitle("Export All Data").Share();
    4.     }
    I'VE FOUND A SOLUTION: POSTING HERE FOR FUTURE INQUIRIES
    So, the solution. In order to send multiple files at once, I had to send the main directory file to a .zip file. To do this, I created a .cs class called compress and used ZipFile to compress the folder:
    Code (CSharp):
    1. //created a method to call from my main class with NativeShare
    2. public void compressToZip(string startPath, string zipPath) {
    3.         ZipFile.CreateFromDirectory(startPath, zipPath);
    4.     }
    Not sure if this was necessary, but I heard that it was, so I added a csc.rsp file to my main assets folder with the code:
    Code (CSharp):
    1. -r:System.IO.Compression.FileSystem.dll
    From here, in my native share class, I used this code:
    Code (CSharp):
    1. public void exportAllDataButton() {
    2.         //Refresh of .zip file necessary to have multiple exports with different data
    3.         if (File.Exists(Application.persistentDataPath + "/Information.zip")) {
    4.             File.Delete(Application.persistentDataPath + "/Information.zip");
    5.         }
    6.  
    7.         compressClass.compressToZip(Application.persistentDataPath + "/Information", Application.persistentDataPath + "/Information.zip");
    8.         new NativeShare().AddFile(Application.persistentDataPath + "/Information.zip").SetSubject("Export From: " + timeText.text).SetTitle("Export All Data").Share();
    9.     }
    A final note: make sure, for both classes, to import System.IO and, for the compression class only, System.IO.Compression. I created this program targeting android; it was successfully tested on that platform.
    Hope this helps!
     
    Last edited: Jul 15, 2019
    yasirkula likes this.
  24. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    @yasirkula Did something change in the plugin on iOS? It seems when we call the Share method, we get a prompt to share, but there is no image attached. Only text.
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
  26. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    @yasirkula Could I ask how to share an image only? I tried doing that by changing my code:
    Code (CSharp):
    1. //Old Way with text
    2. new NativeShare().AddFile(path,"image/jpeg").SetTarget(target).SetTitle("Share Picture").SetSubject(subject)).SetText(text).Share();
    3.                
    4. //New way with image only, does not work
    5. new NativeShare().AddFile(path,"image/jpeg").SetTarget(target).Share();
    But it does not work on iOS.
     
    Last edited: Jul 19, 2019
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Yes that's the way to do it. Which iOS app doesn't accept images? Did it accept images before?

    P.S. You can continue using SetTitle, it won't affect the outcome.
     
  28. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    Ah, I think for some reason it can't find the path at which I'm saving the image. I'm using NativeGallery to take a screenshot.
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Can I see the relevant parts of your code? Especially the part where you retrieve the screenshot's path via NativeGallery would be useful.
     
  30. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    We call this in a MonoBehaviour after taking a screenshot of the game's camera which works:
    Code (CSharp):
    1. Texture2D _saveImage = GetTextureFromScreenshot();
    2. var result = SaveImageToGallery(_saveImage, selfieFileName, (path) =>
    3. {
    4.         #if UNITY_IOS
    5.             new NativeShare().AddFile(path,"image/jpeg").Share();
    6.         #else
    7.             new NativeShare().AddFile(path,"image/jpeg").SetTarget(target).SetTitle("Share Picture").SetSubject(shareText).SetText(link).Share();
    8.         #endif
    9. });
    We call the SaveImageToGallery():
    Code (CSharp):
    1.  public static NativeGallery.Permission SaveImageToGallery(Texture2D texture2D, string title, Action<string> onComplete)
    2.     {
    3.         return NativeGallery.SaveImageToGallery(texture2D, "SelfieAlbum", title, (error, path) =>
    4.         {
    5.             if (path != null)
    6.             {
    7.               onComplete(path);
    8.             }
    9.             if (error != null)
    10.             {
    11.                 Debug.LogError(error);
    12.             }
    13.  
    14.         });
    15.     }
    Which continuing down the method hierarchy gets to this:
    Code (CSharp):
    1.  private static Permission SaveToGallery(byte[] mediaBytes, string album, string filenameFormatted, bool isImage, MediaSaveCallback callback)
    2.     {
    3.         if (mediaBytes == null || mediaBytes.Length == 0)
    4.             throw new ArgumentException("Parameter 'mediaBytes' is null or empty!");
    5.  
    6.         if (album == null || album.Length == 0)
    7.             throw new ArgumentException("Parameter 'album' is null or empty!");
    8.  
    9.         if (filenameFormatted == null || filenameFormatted.Length == 0)
    10.             throw new ArgumentException("Parameter 'filenameFormatted' is null or empty!");
    11.  
    12.         var result = RequestPermission();
    13.         // If we don't have permission, save to persistent data path
    14.         // overwrite last save
    15.         string path = (result == Permission.Granted) ? GetSavePath(album, filenameFormatted) : Application.persistentDataPath + "/scratch.jpg";
    16.  
    17.         // Save Image to Hard Drive in the Editor & Windows PC
    18. #if UNITY_EDITOR || (!UNITY_EDITOR && UNITY_STANDALONE_WIN)
    19.  
    20.         string directory = Path.GetDirectoryName(path);
    21.         if (!Directory.Exists(directory))
    22.         {
    23.             Directory.CreateDirectory(directory);
    24.         }
    25.  
    26. #endif
    27.  
    28.         File.WriteAllBytes(path, mediaBytes);
    29.  
    30.         // if we don't have access to gallery, store in persistent data instead
    31.         if (result == Permission.Granted)
    32.         {
    33.             SaveToGalleryInternal(path, album, isImage, callback);
    34.         }
    35.         else
    36.         {
    37.             callback(null, path);
    38.         }
    39.  
    40.         return result;
    41.     }
     
  31. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    On iOS,
    string path = GetSavePath(...)
    is used only temporarily since the Photos app internally copies the image to its own private storage. That's why NativeGallery doesn't return a filepath in a callback, it is not possible to retrieve the path of an image in Photos, it is an internal path. NativeGallery deletes the temporary file located at
    path
    after it is no longer needed, you can see the removeItemAtPath lines here: https://github.com/yasirkula/UnityN...er/Plugins/NativeGallery/iOS/NativeGallery.mm

    In conclusion, you may want to write the texture's bytes to a temporary file at a path like
    Application.temporaryCachePath + "/image.jpg"
    and then share this file.
     
    Ben-BearFish likes this.
  32. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,184
    I'll try that and tell you how it goes. Thanks for that info.
     
  33. techartsmsm

    techartsmsm

    Joined:
    Jun 18, 2019
    Posts:
    26
    @yasirkula I am using iOS 13, latest beta. When I want to share a video it sometimes crashes, sometimes not. Anything I can do?
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Are there any meaningful error messages in Xcode console? Does this also happen on a fresh new Unity project? What about while sharing only a text?
     
  35. techartsmsm

    techartsmsm

    Joined:
    Jun 18, 2019
    Posts:
    26
    It doesn't work and these error messages come up:


    [B]2019-07-25 00:36:17.039567+0200 samples[2600:881214] [ShareSheet] connection invalidated[/B]

    [B]2019-07-25 00:36:17.039766+0200 samples[2600:882065] [ShareSheet] connection invalidated[/B]

    [B]2019-07-25 00:36:17.157074+0200 samples[2600:880820] Warning: Attempt to present <UIActivityViewController: 0x140303800> on <UnityDefaultViewController: 0x13fd6ae90> while a presentation is in progress![/B]

    [B]2019-07-25 00:36:17.157140+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.158550+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.159418+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.159820+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.159842+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.160060+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.160319+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.160529+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.160685+0200 samples[2600:881214] [Assert] Cannot be called with asCopy = NO on non-main thread.[/B]

    [B]2019-07-25 00:36:17.165788+0200 samples[2600:881214] [Animation] +[UIView setAnimationsEnabled:] being called from a background thread. Performing any operation from a background thread on UIView or a subclass is not supported and may result in unexpected and insidious behavior. trace=([/B]

    [B] 0 UIKitCore 0x00000001a5ecc220 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 15270432[/B]

    [B] 1 UIKitCore 0x00000001a5ecc2b8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 15270584[/B]

    [B] 2 libdispatch.dylib 0x00000001a16cf080 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 12416[/B]

    [B] 3 libdispatch.dylib 0x00000001a16d0768 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 18280[/B]

    [B] 4 UIKitCore 0x00000001a5ecc1a4 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 15270308[/B]

    [B] 5 UIKitCore 0x00000001a5ecc324 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 15270692[/B]

    [B] 6 UIKitCore 0x00000001a50fce28 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 790056[/B]

    [B] 7 UIKitCore 0x00000001a50fd378 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 791416[/B]

    [B] 8 UIKitCore 0x00000001a50fbfcc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 786380[/B]

    [B] 9 UIKitCore 0x00000001a50f9b1c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 776988[/B]

    [B] 10 ShareSheet 0x00000001ad676ed4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 130772[/B]

    [B] 11 ShareSheet 0x00000001ad67a7d4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 145364[/B]

    [B] 12 ShareSheet 0x00000001ad67dea4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 159396[/B]

    [B] 13 ShareSheet 0x00000001ad684300 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 185088[/B]

    [B] 14 UIKitCore 0x00000001a5417ec4 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4046532[/B]

    [B] 15 UIKitCore 0x00000001a541cadc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4066012[/B]

    [B] 16 UIKitCore 0x00000001a541cec8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4067016[/B]

    [B] 17 UIKitCore 0x00000001a5432e74 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4157044[/B]

    [B] 18 UIKitCore 0x00000001a542b93c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4127036[/B]

    [B] 19 UIKitCore 0x00000001a542d328 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4133672[/B]

    [B] 20 UIKitCore 0x00000001a542f96c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143468[/B]

    [B] 21 UIKitCore 0x00000001a542fed0 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4144848[/B]

    [B] 22 UIKitCore 0x00000001a542f8b8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143288[/B]

    [B] 23 UIKitCore 0x00000001a542fb4c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143948[/B]

    [B] 24 Photos 0x00000001ad530604 971A785E-FA25-365C-B512-187539B76814 + 906756[/B]

    [B] 25 AssetsLibraryServices 0x00000001b6790c7c C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 445564[/B]

    [B] 26 AssetsLibraryServices 0x00000001b675c128 C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 229672[/B]

    [B] 27 libdispatch.dylib 0x00000001a16cdc24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 7204[/B]

    [B] 28 libdispatch.dylib 0x00000001a16cf080 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 12416[/B]

    [B] 29 libdispatch.dylib 0x00000001a16d54f8 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 38136[/B]

    [B] 30 libdispatch.dylib 0x00000001a16d5f24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 40740[/B]

    [B] 31 libdispatch.dylib 0x00000001a16def94 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 77716[/B]

    [B] 32 libsystem_pthread.dylib 0x00000001a173ae6c 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 40556[/B]

    [B] 33 libsystem_pthread.dylib 0x00000001a1734a30 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 14896[/B]

    [B] 34 libsystem_pthread.dylib 0x00000001a173ab88 start_wqthread + 8[/B]

    [B])[/B]

    [B]2019-07-25 00:36:17.174781+0200 samples[2600:881214] This application is modifying the autolayout engine from a background thread after the engine was accessed from the main thread. This can lead to engine corruption and weird crashes.[/B]

    [B] Stack:([/B]

    [B] 0 Foundation 0x00000001a1f10058 5F54DAFC-E48D-374F-A95D-218055C1D62A + 2326616[/B]

    [B] 1 Foundation 0x00000001a1d00ad8 5F54DAFC-E48D-374F-A95D-218055C1D62A + 166616[/B]

    [B] 2 UIKitCore 0x00000001a5e08fa8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14471080[/B]

    [B] 3 UIKitCore 0x00000001a5e0957c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14472572[/B]

    [B] 4 UIKitCore 0x00000001a5e08d5c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14470492[/B]

    [B] 5 UIKitCore 0x00000001a5e07e74 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14466676[/B]

    [B] 6 UIKitCore 0x00000001a5e094fc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14472444[/B]

    [B] 7 UIKitCore 0x00000001a5dfd0a8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14422184[/B]

    [B] 8 UIKitCore 0x00000001a5dfd70c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14423820[/B]

    [B] 9 Foundation 0x00000001a1cffb90 5F54DAFC-E48D-374F-A95D-218055C1D62A + 162704[/B]

    [B] 10 ShareSheet 0x00000001ad6778c8 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 133320[/B]

    [B] 11 ShareSheet 0x00000001ad67a7d4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 145364[/B]

    [B] 12 ShareSheet 0x00000001ad67dea4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 159396[/B]

    [B] 13 ShareSheet 0x00000001ad684300 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 185088[/B]

    [B] 14 UIKitCore 0x00000001a5417ec4 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4046532[/B]

    [B] 15 UIKitCore 0x00000001a541cadc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4066012[/B]

    [B] 16 UIKitCore 0x00000001a541cec8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4067016[/B]

    [B] 17 UIKitCore 0x00000001a5432e74 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4157044[/B]

    [B] 18 UIKitCore 0x00000001a542b93c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4127036[/B]

    [B] 19 UIKitCore 0x00000001a542d328 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4133672[/B]

    [B] 20 UIKitCore 0x00000001a542f96c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143468[/B]

    [B] 21 UIKitCore 0x00000001a542fed0 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4144848[/B]

    [B] 22 UIKitCore 0x00000001a542f8b8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143288[/B]

    [B] 23 UIKitCore 0x00000001a542fb4c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143948[/B]

    [B] 24 Photos 0x00000001ad530604 971A785E-FA25-365C-B512-187539B76814 + 906756[/B]

    [B] 25 AssetsLibraryServices 0x00000001b6790c7c C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 445564[/B]

    [B] 26 AssetsLibraryServices 0x00000001b675c128 C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 229672[/B]

    [B] 27 libdispatch.dylib 0x00000001a16cdc24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 7204[/B]

    [B] 28 libdispatch.dylib 0x00000001a16cf080 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 12416[/B]

    [B] 29 libdispatch.dylib 0x00000001a16d54f8 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 38136[/B]

    [B] 30 libdispatch.dylib 0x00000001a16d5f24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 40740[/B]

    [B] 31 libdispatch.dylib 0x00000001a16def94 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 77716[/B]

    [B] 32 libsystem_pthread.dylib 0x00000001a173ae6c 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 40556[/B]

    [B] 33 libsystem_pthread.dylib 0x00000001a1734a30 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 14896[/B]

    [B] 34 libsystem_pthread.dylib 0x00000001a173ab88 start_wqthread + 8[/B]

    [B])[/B]

    [B]2019-07-25 00:36:17.184904+0200 samples[2600:881214] Uncaught exception: NSInternalInconsistencyException: Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.[/B]

    [B]([/B]

    [B] 0 CoreFoundation 0x00000001a1a27354 517BD051-249C-3BC3-BBCD-E64783E9CC11 + 1254228[/B]

    [B] 1 libobjc.A.dylib 0x00000001a1742388 objc_exception_throw + 60[/B]

    [B] 2 Foundation 0x00000001a1f100e8 5F54DAFC-E48D-374F-A95D-218055C1D62A + 2326760[/B]

    [B] 3 Foundation 0x00000001a1d00ad8 5F54DAFC-E48D-374F-A95D-218055C1D62A + 166616[/B]

    [B] 4 UIKitCore 0x00000001a5e08fa8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14471080[/B]

    [B] 5 UIKitCore 0x00000001a5e0957c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14472572[/B]

    [B] 6 UIKitCore 0x00000001a5e08d5c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14470492[/B]

    [B] 7 UIKitCore 0x00000001a5e07e74 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14466676[/B]

    [B] 8 UIKitCore 0x00000001a5e094fc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14472444[/B]

    [B] 9 UIKitCore 0x00000001a5dfd0a8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14422184[/B]

    [B] 10 UIKitCore 0x00000001a5dfd70c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 14423820[/B]

    [B] 11 Foundation 0x00000001a1cffb90 5F54DAFC-E48D-374F-A95D-218055C1D62A + 162704[/B]

    [B] 12 ShareSheet 0x00000001ad6778c8 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 133320[/B]

    [B] 13 ShareSheet 0x00000001ad67a7d4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 145364[/B]

    [B] 14 ShareSheet 0x00000001ad67dea4 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 159396[/B]

    [B] 15 ShareSheet 0x00000001ad684300 DFB470DB-AC8B-33EA-98C8-1DB9EF927F81 + 185088[/B]

    [B] 16 UIKitCore 0x00000001a5417ec4 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4046532[/B]

    [B] 17 UIKitCore 0x00000001a541cadc 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4066012[/B]

    [B] 18 UIKitCore 0x00000001a541cec8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4067016[/B]

    [B] 19 UIKitCore 0x00000001a5432e74 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4157044[/B]

    [B] 20 UIKitCore 0x00000001a542b93c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4127036[/B]

    [B] 21 UIKitCore 0x00000001a542d328 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4133672[/B]

    [B] 22 UIKitCore 0x00000001a542f96c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143468[/B]

    [B] 23 UIKitCore 0x00000001a542fed0 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4144848[/B]

    [B] 24 UIKitCore 0x00000001a542f8b8 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143288[/B]

    [B] 25 UIKitCore 0x00000001a542fb4c 15FE3BB2-ABD9-33D1-8641-E04B229B3F7A + 4143948[/B]

    [B] 26 Photos 0x00000001ad530604 971A785E-FA25-365C-B512-187539B76814 + 906756[/B]

    [B] 27 AssetsLibraryServices 0x00000001b6790c7c C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 445564[/B]

    [B] 28 AssetsLibraryServices 0x00000001b675c128 C70D807B-5FD2-37DD-B541-AB0FDB5148EA + 229672[/B]

    [B] 29 libdispatch.dylib 0x00000001a16cdc24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 7204[/B]

    [B] 30 libdispatch.dylib 0x00000001a16cf080 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 12416[/B]

    [B] 31 libdispatch.dylib 0x00000001a16d54f8 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 38136[/B]

    [B] 32 libdispatch.dylib 0x00000001a16d5f24 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 40740[/B]

    [B] 33 libdispatch.dylib 0x00000001a16def94 4DEFEF54-4DE0-35EC-BB0E-32138324C258 + 77716[/B]

    [B] 34 libsystem_pthread.dylib 0x00000001a173ae6c 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 40556[/B]

    [B] 35 libsystem_pthread.dylib 0x00000001a1734a30 1FE3BD15-61AF-3F0C-9CC8-2598FED6E7A3 + 14896[/B]

    [B] 36 libsystem_pthread.dylib 0x00000001a173ab88 start_wqthread + 8[/B]

    [B])[/B]

    [B]2019-07-25 00:36:17.188111+0200 samples[2600:881214] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.'[/B]

    [B]*** First throw call stack:[/B]

    [B](0x1a1a27340 0x1a1742388 0x1a1f100e8 0x1a1d00ad8 0x1a5e08fa8 0x1a5e0957c 0x1a5e08d5c 0x1a5e07e74 0x1a5e094fc 0x1a5dfd0a8 0x1a5dfd70c 0x1a1cffb90 0x1ad6778c8 0x1ad67a7d4 0x1ad67dea4 0x1ad684300 0x1a5417ec4 0x1a541cadc 0x1a541cec8 0x1a5432e74 0x1a542b93c 0x1a542d328 0x1a542f96c 0x1a542fed0 0x1a542f8b8 0x1a542fb4c 0x1ad530604 0x1b6790c7c 0x1b675c128 0x1a16cdc24 0x1a16cf080 0x1a16d54f8 0x1a16d5f24 0x1a16def94 0x1a173ae6c 0x1a1734a30 0x1a173ab88)[/B]

    [B]libc++abi.dylib: terminating with uncaught exception of type NSException[/B]

    [B](lldb) [/B]




    Help would be greatly appreciated as I need to ship a prototype soon :)
     
  36. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Are you calling NativeShare.Share() from a separate thread? Does trying the example code on a fresh new project also yield the same result? Can you enable "Development Build" to see if the error messages show any stacktrace?
     
    techartsmsm likes this.
  37. techartsmsm

    techartsmsm

    Joined:
    Jun 18, 2019
    Posts:
    26
    Thanks a lot! The seperate thread fixed it. I didn't know that was necessary.
     
  38. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Actually, calling the Share function from a separate thread was the thing I was suggesting you to avoid as it can result in crashes. I'm surprised to hear that using a separate thread has worked for you :O
     
  39. techartsmsm

    techartsmsm

    Joined:
    Jun 18, 2019
    Posts:
    26
    Okay, interesting. Why is it in the example code then? :)
     
  40. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Example code doesn't use a separate thread, it calls the Share function from the main thread.
     
  41. garysyndromes

    garysyndromes

    Joined:
    Jun 26, 2019
    Posts:
    2
    Hello sir, Thank you very much for your plug in. I am experiencing some problems with using it though, My Unity 2019.1.8f1 cant seem to detect the NativeShare() type when i am using your code.
    I have ensured that I made the appropriate Android setup from https://github.com/yasirkula/UnityNativeShare#android-setup
    and when I use the example code, I am getting an error on my text editor
    "
    Assets\Vuforia\Scripts\Screenshot\ShareScript.cs(30,13): error CS0246: The type or namespace name 'NativeShare' could not be found (are you missing a using directive or an assembly reference?) " please help!
     
  42. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Are you using an Assembly Definition asset in your Vuforia directory? Try moving
    ShareScript.cs
    to
    Assets\ShareScript.cs
    and see if it changes anything.
     
  43. garysyndromes

    garysyndromes

    Joined:
    Jun 26, 2019
    Posts:
    2
    It works now! Thank you so much for your help! May i know why does it not work when it is in the inner folder?
     
  44. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    I'm guessing that the scripts inside the Vuforia directory (assembly A) are compiled before the scripts inside the Plugins directory (which contains NativeShare, assembly B). If A is compiled before B and A has no explicit reference to B (AFAIK, specified inside the Assembly Definition asset), then scripts in A can't access scripts in B.
     
  45. blackhawk_001

    blackhawk_001

    Joined:
    Jan 25, 2019
    Posts:
    11
    @yasirkula hi, thanks for this plugin. great plugin man. can i ask whether this plugin capable to connect with bluetooth printer?
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    I've never tried it. It creates an
    ACTION_SEND
    intent on Android and
    UIActivityViewController
    on iOS. If those support bluetooth printer, then this plugin should be capable of connection to the printer.
     
  47. nhminh0701

    nhminh0701

    Joined:
    Jul 29, 2019
    Posts:
    1
    When I use ScreenCapture.CaptureScreenShot(filename); and then NativeShare.AddFile(Path.Combine(Application.persistentDatapath, filename), I could not share the image eventhough the destination was correct, but writing bytes[] like your demo worked... so what is the issue here?
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    From ScreenCapture.CaptureScreenShot:
    Basically, the screenshot doesn't yet exist at the path when you call the Share function.
     
  49. MisterBorogove

    MisterBorogove

    Joined:
    Aug 8, 2017
    Posts:
    1
    Hey, I don't have any questions or problems, but I dropped Native Share into my project today and it works, and you're in here giving support on your free thing for over a year, so thank you and great work!
     
    yasirkula likes this.
  50. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,186
    Much appreciated :)