Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Native Gallery for Android & iOS [Open Source]

Discussion in 'Assets and Asset Store' started by yasirkula, Feb 28, 2018.

  1. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Maybe if your phone was connected to your computer via a USB cable, SD card switched to read-only mode. Try unplugging the device and then saving the image to gallery. Otherwise, I honestly have no idea.
     
  2. unity_yUAfSYVSfFt1sA

    unity_yUAfSYVSfFt1sA

    Joined:
    Aug 31, 2018
    Posts:
    5
    Thank you, I did too, but still don't work tho.
     
  3. anandapoudel1

    anandapoudel1

    Joined:
    Jan 30, 2017
    Posts:
    4
    @yasirkula +++++ for creating a great plugin. It works great however I have a question, is it possible to select album folders from the gallery instead of selecting multiple images? also Is there a way I can override my albums folders content rather than having duplicate images?
     
  4. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Thanks! NativeGallery simply sends a request to the native gallery app and waits for a response from it. Unfortunately, it is not possible to alter the behaviour of the gallery app in such ways.
     
  5. look001

    look001

    Joined:
    Mar 23, 2017
    Posts:
    41
    yasirkula likes this.
  6. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Thanks for reporting this! I'll update my plugin(s) accordingly soon.
     
    spaolo1234 likes this.
  7. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    I've updated the GitHub repository, update for the Asset Store version should be live in a few days.
     
    spaolo1234 likes this.
  8. CorstiaanMediamonks

    CorstiaanMediamonks

    Joined:
    Sep 14, 2015
    Posts:
    9
    Hi @yasirkula , love the plugin, thnx for that!
    I do have a small issue with NativeGallery.GetImageFromGallery(). Although I'm using mimeType "image/jpeg" the gallery still shows GIF (NativeGallery.GetImageProperties(path) says mime GIF) and even movies without mimeType set. Any idea how we can filter on just JPG? Or even just images would be great.

    using:
    Unity 2017.4.8f1
    Android 8.1.0
    Samsung Note 9
     
  9. CorstiaanMediamonks

    CorstiaanMediamonks

    Joined:
    Sep 14, 2015
    Posts:
    9
    Strange.. when I fall back to "images/*" the movies are gone. Fine for now.
     
  10. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Mime type is passed as a parameter to the gallery application but it is up to the gallery application to respect that filter. On some devices, as you noticed, it might not work. However, you should be able to load most, if not all, of the images in the gallery via the NativeGallery.LoadImageAtPath function.
     
  11. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    34
    Rated 5 stars!!
    @yasirkula : Why i couldn't save texture2d to persistent data path on android? here my code:

    Code (CSharp):
    1.     public void PickImage(SpriteRenderer img, 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.                     sp = Sprite.Create(texture, new Rect(0,0, texture.width, texture.height), new Vector2(0.5f,0.5f));
    16.                     img.sprite = sp;
    17.    
    18.                 }
    19.             }, "Select a PNG image", "image/png", maxSize );
    20.  
    21.         Debug.Log( "Permission result: " + permission );
    22.  
    23.  
    24.  
    25.     }
    26.  
    This is the code that sprite doesn't save to persistent data path:
    Code (CSharp):
    1.     public void SaveImageToDisk(SpriteRenderer img, string filename)
    2.     {
    3. //        SpriteRenderer renderer = img.GetComponent<SpriteRenderer> ();
    4.         Texture2D tempTexture = img.sprite.texture;
    5.         byte[] bytes = tempTexture.EncodeToJPG();
    6.         File.WriteAllBytes (Application.persistentDataPath + filename, bytes);
    7.     }
    8.  
    any help would be appreciated
     
    Last edited: Sep 20, 2018
  12. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    I have two suggestions:

    1) Use
    Path.Combine( Application.persistentDataPath, filename )
    inside File.WriteAllBytes function
    2) tempTexture.EncodeToJPG() can raise an exception if the texture is marked as non-readable. In this case, try not marking the loaded textures as non-readable:
    NativeGallery.LoadImageAtPath( path, maxSize, false )
     
  13. nikosurfing

    nikosurfing

    Joined:
    Mar 11, 2014
    Posts:
    34
    @yasirkula : I am surprised, method number 2 just very simple to change textures as non-readable, i was though so complicated before this. You saved my day... Great support and great plugin. Thank you very much..
     
    Last edited: Sep 21, 2018
  14. aesparza

    aesparza

    Joined:
    Apr 4, 2016
    Posts:
    29
    Hi! Thank you for such plugin! I would like to know if there is any possibility to read from an image metadata (EXIF) its geolocation.

    I'm using it for Unity Android

    Could you please help me?
    Thanks in advance!
     
  15. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Not with NativeGallery, sorry. You'd probably have to write a custom native Android code for that.
     
  16. Annopolus

    Annopolus

    Joined:
    Apr 15, 2015
    Posts:
    14
    What is the easiest way (for both Android and iOS) to do this 2 simple steps:
    1. save one picture (texture in fact) - I'm doing here some simple gfx operations combining camera with some texts.
    2. and immediately after save - loading just saved texture into another image (let's say preview image), just to be sure how final result of GFX operations looks like.

    For the 1st step I'm using NativeGallery.SaveImageToGallery(mySourcePict, "Test", fileName); and it works fine. But I completely don't know how to reload saved picture to myPreviewPict in the 2nd step?

    I stuck with paths which are required for LoadImageAtPath. What path should I provide? I red somewhere above, that on Android I cant use physical path. On iOS even worse (this story with persistent path), however I didnt tested that one yet, as I'm on Android stage right now.
     
  17. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Why not assign mySourcePict to the Image? If you are trying to make sure that NativeGallery saves the image correctly, you can do so via the Gallery itself.
     
  18. OtterBane

    OtterBane

    Joined:
    Sep 22, 2018
    Posts:
    2
    Hi @yasirkula !

    Fist of all, great plugin, huge respect! I would like to ask you if direct access - so without the picture selector from the gallery popping up - is possible to image files? I'm planning the following:
    1. Fetching gallery path from device (iOS or Android)
    2. Reading images (not all of course at once, but batched)
    Based on your knowledge on iOS / Android, can this be achieved by using your plugin or extending it with a few functions? Or due to operating system restrictions is it impossible without triggering the picture selector popup?

    Thanks a lot,
    Bane
     
  19. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Hi Bane,

    These things should be possible on both platforms because there are a number of open-source image/video selectors out there that must have access to these files somehow. However, it is not possible with NativeGallery, you have to create your own solution from scratch (you can use NativeGallery.LoadImageAtPath to load the images, though).

    1. The issue here is that, there is not really a Gallery folder on Android; images showing up in the gallery can be located at almost anywhere on the device. So, you may have to traverse your phone's drive recursively to find all the pictures.

    2. In this one, make sure to read only a small thumbnail from each image as textures created at runtime are not compressed in Unity and thus, loading large images can quickly consume all the available memory on your device.
     
  20. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    will this allow for me to obtain list of photos from users gallery and display them in my own custom gallery viewer?
     
  21. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Unfortunately not. NativeGallery lets the native Gallery app handle all these jobs.
     
  22. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    310
    Hey yasirkula,

    Firstly I'd like to thank you for developing the plugin and making it available for free.

    Second i'd like to ask for help on an issue we've been having lately for Android. The gallery is no longer opening on Android. I am also not even prompted for permission.
    The gallery was opening fine and all until a few days ago, possibly after an android update. I've tested on Android 8 Oreo and Android 9 Pie and I still can't open it. However, the same code works fine for IOS and the gallery opens fine there. I uptated to the latest version available on the asset store 1.2 and I still have the issue.
    Here is how I'm calling it, maybe there is something I'm missing.
    Code (CSharp):
    1.     private void OpenAndroidOrIOSGallery(Image image)
    2.     {
    3.         int maxSize = image == miniLogo ? 16 : 200;
    4.         GameUtils.ShowFloatingMessage("Opening Image Gallery");
    5.         NativeGallery.GetImageFromGallery((path) =>
    6.         {
    7.             GameUtils.ShowFloatingMessage("Inside path");
    8.             if (path != null)
    9.             {
    10.                 Texture2D texture = NativeGallery.LoadImageAtPath(path, maxSize, false);
    11.                 SetLoadedTexture(image, texture);
    12.             }
    13.             else
    14.             {
    15.                 GameUtils.ShowFloatingMessage("Invalid image Path");
    16.             }
    17.         }, "Select a JPG or PNG image", "image/png,image/jpeg", maxSize);
    18.     }
    I get the debug message for "Opening Image Gallery" but I never get the message "Inside path" when I'm no Android. I do get it on IOS.

    Debugging with logcat didn't throw any message.
     
  23. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Try replacing "image/png,image/jpeg" with "image/*". NativeGallery.LoadImageAtPath can load most, if not all, image types anyways, so that shouldn't be a problem.
     
  24. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    310
    Thanks for the reply, I changed the line as you suggested but I still didn't see any difference. When I click it it just seems to never be executing the MediaPickCallback callback. Do you have any other suggestion?
     
  25. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    Check if GetImageFromGallery returns Permission.Denied. If this is the case, uninstall the app, reinstall it and then see if it still doesn't prompt for permission.
     
  26. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    310
    I went in your RequestPermission() and I debugged on logcat "Debug.Log(nativeCallback.Result);".
    It is giving me 0 as result. Here is the rest:

    Code (CSharp):
    1. 09-27 17:17:17.519  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    2. 09-27 17:17:17.519  3052  3081 I Unity   :
    3. 09-27 17:17:20.188  3052  3081 I Unity   : RequestPermission
    4. 09-27 17:17:20.188  3052  3081 I Unity   :
    5. 09-27 17:17:20.188  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    6. 09-27 17:17:20.188  3052  3081 I Unity   :
    7. 09-27 17:17:20.190  3052  3081 I Unity   : NGPermissionCallbackAndroid
    8. 09-27 17:17:20.190  3052  3081 I Unity   :
    9. 09-27 17:17:20.190  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    10. 09-27 17:17:20.190  3052  3081 I Unity   :
    11. 09-27 17:17:24.224  3052  3052 W Unity   : Timeout while trying to pause the Unity Engine.
    12. 09-27 17:17:24.276  3052  3081 I Unity   : (Permission) nativeCallback.Result
    13. 09-27 17:17:24.276  3052  3081 I Unity   :
    14. 09-27 17:17:24.276  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    15. 09-27 17:17:24.276  3052  3081 I Unity   :
    16. 09-27 17:17:24.276  3052  3081 I Unity   : 0
    17. 09-27 17:17:24.276  3052  3081 I Unity   :
    18. 09-27 17:17:24.276  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    19. 09-27 17:17:24.276  3052  3081 I Unity   :
    20. 09-27 17:18:25.920  3052  3081 I Unity   : RequestPermission
    21. 09-27 17:18:25.920  3052  3081 I Unity   :
    22. 09-27 17:18:25.920  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    23. 09-27 17:18:25.920  3052  3081 I Unity   :
    24. 09-27 17:18:25.920  3052  3081 I Unity   : NGPermissionCallbackAndroid
    25. 09-27 17:18:25.920  3052  3081 I Unity   :
    26. 09-27 17:18:25.920  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    27. 09-27 17:18:25.920  3052  3081 I Unity   :
    28. 09-27 17:18:25.922  3052  3081 I Unity   : 0
    29. 09-27 17:18:25.922  3052  3081 I Unity   :
    30. 09-27 17:18:25.922  3052  3081 I Unity   : (Filename: /Users/builduser/buildslave/unity/build/artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
    31. 09-27 17:18:25.922  3052  3081 I Unity   :
    Could that timeout be an issue? I did get a 1-2 second pause while trying to open for the first time. The subsequent tries didn't take that long and resulted in not opening straight away.
    I'm making a new build now with the propper, "NativeGallery.Permission permission" in your examples. It just takes a while as I use cloud.

    Unfortunately, uninstalling the app had no effect.
     
    Last edited: Sep 27, 2018
  27. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    0 means Denied permission. Can you verify that your final AndroidManifest has WRITE_EXTERNAL_STORAGE permission in it (without any maxSdkVersion-like attributes)? Also, when you navigate to Settings for your app, is Storage permission defined there? If you test the plugin on a new project using the example code, does it work properly?

    BTW, the timeout shouldn't be the cause of this issue, it happens to me, as well.
     
    FernandoHC likes this.
  28. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    310
    Thanks for the help, yasirkula.

    I added the following lines to the manifest:
    Code (CSharp):
    1.   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    2.   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    and also changed the Android->Other Settings->Configuration->Write Permission from "Internal" to "External (SDCard)".

    I now get the permission asked the first time I run the app. If I chose to allow then it doesn't ask again, if I deny then your request permission is displayed normally and the gallery works fine :)

    Really appreciate the help there, but just to close this one, would it be possible to not have the permission request to be displayed when I open the app, but rather only when I try to open the gallery? This used to work before so I'm sure it;s possible, just not sure which option triggers that.

    Also, I never use the gallery to write so I'm not sure write permission is necessary, as I only read from it.
     
  29. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    If your other plugins don't request any permissions at startup, you can surely do that. See "Runtime permissions" section here: https://docs.unity3d.com/Manual/android-manifest.html

    For simplicity's sake, NativeGallery requests both permissions simultaneously. Although it is a good idea to ask only the read permission in your case, it is not supported by NativeGallery yet.
     
    FernandoHC likes this.
  30. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    310
    Interesting, good to know. So maybe I want to manage permissions myself before I try to use any plugin. Apparently unity doesn't have any built in ways to ask for specific permissions at runtime so i'd have to do some research on how do it.

    Thanks for the help again!
     
  31. PhilippeGe

    PhilippeGe

    Joined:
    Sep 17, 2017
    Posts:
    6
    Hi,
    I have no problem to use NativeGallery.GetVideoFromGallery(path) on android.
    but on IOS, when i pick a video, it automatically compress it after i picked it. How can we avoid that?
    Thanks a lot
     
  32. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    PhilippeGe likes this.
  33. efge

    efge

    Joined:
    Dec 13, 2007
    Posts:
    55
    Thanks a lot for this plugin! Would definitely pay for it :)

    One question (iOS):
    Is it possible to get a callback or similar when the user cancels the photo pick?

    The only feedback from Xcode is:
    [discovery] errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}


    Thank you!
     
  34. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    It is supposed to call the MediaPickCallback with null parameter. Is it not the case for you?
     
  35. elpuerco63

    elpuerco63

    Joined:
    Jun 26, 2014
    Posts:
    271
    Ah OK thanks. Do you know if this is at all possible via Unity or am I simply running down a rabbit hole?

    I need to provide a gallery of users photos which will allow the user to drag any of them to a edit board on another part of the screen....
     
  36. efge

    efge

    Joined:
    Dec 13, 2007
    Posts:
    55
    path == null
    does the job.

    Thanks!
     
    yasirkula likes this.
  37. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
  38. shin_unity197

    shin_unity197

    Joined:
    Oct 30, 2017
    Posts:
    18
    @yasirkula
    Code (CSharp):
    1. NativeGallery.SaveImageToGallery(m_screenTexture, "AlbumName", "Img_{0}.png");
    If I execute the code above, should it place an image called "Img_0.png" in AlbumName? At the moment, it places the "Img_0.png" in the Camera folder. Is this the correctly behavior or am I missing something? Does the folder need to exist beforehand?
     
    Last edited: Oct 1, 2018
  39. Bavrogar

    Bavrogar

    Joined:
    Nov 24, 2017
    Posts:
    2
    I have a small problem on Android: When my app is started for the first time after installing it, LoadImageAtPath doesn't work, the imagePath is correct, but !File.Exists( imagePath ) returns true. However, after restarting the app it suddenly works with no problem. Selecting images with GetImagesFromGallery works just fine on the first boot and CheckPermission also returns "Granted". Any Idea what could be causing this?
     
  40. PhilippeGe

    PhilippeGe

    Joined:
    Sep 17, 2017
    Posts:
    6
    Thanks a lot. i added
    if (@available(iOS 11.0, *)) {
    imagePicker.videoExportPreset = AVAssetExportPresetPassthrough;
    }
    as you advised. I still have the quick compression process. I dont really know if it compresses though?
    I Can show the path of this video. Thanks
    Is there a way to avoid the compression window? i know some people might have asked you. but you might have found something since then?
    great plug in on Android, it really works great. thanks
     
  41. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    @shin_unity197 It should place an image called "Image_0.png" in DCIM/AlbumName on Android and in AlbumName album on iOS. These directories don't have to exist beforehand. Honestly, I haven't seen it saving the image inside the Camera directory before, so I am kind of clueless here. On which device did you test it? Does the example code also not work correctly?

    @Bavrogar Make sure to call LoadImageAtPath inside the MediaPickCallback of the GetImagesFromGallery function. For example, please see the example code. If you are already doing so, can you please check if the same problem also exists on the GetImageFromGallery function? Did you test it on iOS or Android?

    @PhilippeGe Unfortunately not. I don't think Apple added an option to skip the compression part completely, as I couldn't find a working solution on google.
     
  42. shin_unity197

    shin_unity197

    Joined:
    Oct 30, 2017
    Posts:
    18
    @yasirkula I'm on the Google Pixel 2 and it yes I'm using the exact snippet of code shown in the example code and it doesn't work. All my saves are going into the Camera Directory
     
    Last edited: Oct 3, 2018
  43. OtterBane

    OtterBane

    Joined:
    Sep 22, 2018
    Posts:
    2
    Hi @yasirkula ,

    Thanks for the advice before. Now I'm using a dispatcher code to open the gallery selector if in iOS. However, how do you handle when someone returns with pressing 'Cancel' in the image selection? It seems that the iOS runs into an endless loop until you "return" somehow to the scene. Have you met this behavior before?

    Thanks,
    Bane
     
  44. Cascho01

    Cascho01

    Joined:
    Mar 19, 2010
    Posts:
    1,101
    I use another plugin to let the user save a screenshot into the iOS camera roll.
    Now I want to automatically open this particular image with the native gallery app.
    Is this possible (with your plugin)?
     
    Last edited: Oct 5, 2018
  45. Bavrogar

    Bavrogar

    Joined:
    Nov 24, 2017
    Posts:
    2
    @yasirkula It appears that my problem only occurs when testing the app on an Android emulator. Thought I had already tested it on my Android phone but appearantly not, because it works there with no problem.
    However I do call both LoadImagesAtPath and LoadImageAtPath outside of the Callback in some instances, can that lead to issues?
    Also whether or not the Load-functions are called within the Callback doesn't make a difference for my original problem (which seems to just be limited to my emulator though, so probably not really an issue).
     
  46. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
    @shin_unity197 I honestly have no idea why this happens with NativeGallery, sorry :/

    @OtterBane I didn't test it with dispatcher code myself but normally such an issue shouldn't occur unless your code keeps asking for an image until an image is selected.

    @Cascho01 Unfortunately not.

    @Bavrogar The recommended way is to use LoadImageInPath inside the callback because otherwise, it doesn't work correctly on iOS. However, I'm not sure why this function doesn't work correctly on your Android emulator even when it is located inside the callback.
     
  47. PhilippeGe

    PhilippeGe

    Joined:
    Sep 17, 2017
    Posts:
    6
    Hello @yasirkula
    Sorry to bother you. i am really struggling on iOS, using a video picked with your plugin and use it as videotexture for sprite or just even play with Videoplayer. I see in your example code that you are using "Handheld.PlayFullScreenMovie" (which is working for me too) but does it mean that a video cannot be used as a texture or with the unity Videoplayer?
    thanks... if someone as a sample code that just pick a video and apply to the videoplayer to play in it, in iOS that would be awesome. thanks a lot
     
  48. yasirkula

    yasirkula

    Joined:
    Aug 1, 2011
    Posts:
    1,022
  49. mrgreaper

    mrgreaper

    Joined:
    Aug 6, 2017
    Posts:
    18
    I am getting a strange issue.
    I have two cameras in my scene
    camera1 is the display the user sees
    camera2 is a display that shows a blank piece of paper and the text that is to be shared/saved as needed

    the following two methods are in the same script and attached to camera2:

    Code (CSharp):
    1. private IEnumerator TakeScreenshotAndSave()
    2.     {
    3.         //Debug.Log("Coroutine started");
    4.         yield return new WaitForEndOfFrame();
    5.  
    6.         Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    7.         texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
    8.         texture.Apply();
    9.         //Debug.Log("texture made");
    10.         Debug.Log("Permission result: " + NativeGallery.SaveImageToGallery(texture, "Dms Lil Helper", "Saved {0}.png"));
    11.         //Debug.Log("texture saved");
    12.         Destroy(texture);
    13.     }
    14.  
    15.     IEnumerator shareImage()
    16.     {
    17.         Texture2D texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
    18.         texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
    19.         texture.Apply();
    20.         string filePath = Path.Combine(Application.temporaryCachePath, "shared img.png");
    21.         File.WriteAllBytes(filePath, texture.EncodeToPNG());
    22.         Destroy(texture);
    23.         new NativeShare().AddFile(filePath).SetSubject("Dms Lil Helper share").Share();
    24.         yield return null;
    25.     }
    26.  
    27.  

    When a player clicks "share image" a boolean is set in this script that displays a message "hey buddy were processing, expect freeze" and then sets another boolean
    when the second boolean is detected in OnPostRender() it then triggers the share function
    this shares an image of camera2 successfully and all is well
    Now when someone clicks the save image button the same process is started but the "TakeScreenshotAndSave" function is called instead this however saves an image of camera1 not camera2
    the save button is setup exactly the same as the share button, both using the game object of camera2 both the code for creting the texture2d is identical in both functions but for some reason the nativegallery plugin is saving an image of camera 1.

    I am aware your the developer of both plugins being used (dear god thank you for providing these!) is there something native gallery is doing differently that is causing an issue?
    and....how do I fix it/can I fix it?



    ***EDIT*** SOLVED
    I am an idiot.
    I have been staring at my code for over an hour trying to fix this, then when I posted it I realised that I had different Yeld triggers (I am a hobby developer and learning as I go so yeld is something that only makes half sense to me) changed the save image yeld to the same as it is on the share image and bingo it works!

    will leave this here incase someone has the same issue (example code yeld state means it will always save an image of whats on the screen not the camera its attached to, which I guess is most peoples use case)
     
    Last edited: Oct 15, 2018
    yasirkula likes this.
  50. Ibukii

    Ibukii

    Joined:
    Jun 23, 2016
    Posts:
    45
    Hi I've tried to change all the settings as you specified on iOS but couldn't get it to work. For Android it works fine already. Is there any information that you need so the troubleshooting is easier? :)

    Edit: I've doubled checked the info and build settings in XCode and it should be like what you specified.

    Edit2: Figured out the issue. The API for iOS must be using GetImageFromGallery instead of GetImagesFromGallery. Just a suggestion to maybe add a error log so users know of this issue (Currently no log appears)
     
    Last edited: Oct 18, 2018