Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS 14 permissions handling #136

Closed
MaryamSaeed opened this issue Aug 16, 2020 · 57 comments
Closed

IOS 14 permissions handling #136

MaryamSaeed opened this issue Aug 16, 2020 · 57 comments

Comments

@MaryamSaeed
Copy link

Description:
i used the example written in the wiki ,When i change permission of photos to “selected photos” then attempting to save an image it does not get saved.
suggestion :
add a value to enum NativeGallery.Permission to handle “selected photos” permission.

  • unity version : 2019.3
  • device : Iphone XR
  • IOS version : 14

MicrosoftTeams-image

@yasirkula
Copy link
Owner

yasirkula commented Aug 17, 2020

I may not be able to resolve this issue until I get my hands on an iOS 14 device but thanks for reporting it.

@MaryamSaeed
Copy link
Author

how about you update it and i will test it for you?
if its okay with you

@yasirkula
Copy link
Owner

Do you get any error messages in Xcode console when attempting to save an image?

@MaryamSaeed
Copy link
Author

okay i will get you the full logs as soon as possible (y)

@MaryamSaeed
Copy link
Author

yup its the same problem :(

@yasirkula
Copy link
Owner

For reference, here's the possible solution to this problem: https://mackuba.eu/2020/07/07/photo-library-changes-ios-14/

@yasirkula
Copy link
Owner

yasirkula commented Sep 13, 2020

@MaryamSaeed I've added the following features to the plugin:

  • switched to PHPickerViewController on iOS 14+, adding the ability to pick multiple images/videos on iOS 14+
  • iOS 14 permissions support: added LimitedAccess to Permission enum
  • added NativeGallery.PermissionFreeMode boolean: when it is set to true, picking media from Photos will not require any permissions on iOS 11+ but the metadata of the picked media may not always be retrieved
  • CheckPermission and RequestPermission functions now take either PermissionType.Read or PermissionType.Write argument
  • When Permission is LimitedAccess, TryExtendLimitedAccessPermission can be called to prompt the user to extend their limited selection
  • Live photos can now be selected while picking images

UPDATE (09/17): on iOS 14, when PermissionFreeMode is set to true, SaveImageToGallery/SaveVideoToGallery will ignore the album parameter: #136 (comment)

Download: redacted, simply download the latest version of the plugin

Unfortunately, I couldn't test most of these features because Unity doesn't support iOS 14 simulators and I don't have an iOS 14 device.

The features I really wanted to test on iOS 14 are:

  • picking multiple images/videos
  • picking live photos and checking if the returned image can be loaded with LoadImageAtPath without any issues (including orientation issues)(it won't be animated but that's expected)
  • picking HEIC images and checking if the returned path points to a .heic file and the image can be loaded with LoadImageAtPath without any issues
  • picking HEVC videos and checking if the returned path points to a .hevc file and the video can be previewed with Handheld.PlayFullScreenMovie or VideoPlayer
  • picking gif images in PermissionFreeMode and seeing if the returned path points to a .gif image (preferred) or a .png image
  • saving an image to Photos when full Photos access isn't granted (I suspect that the image will be saved to the default Camera Roll album instead of the custom album in this case). This must be tested in 2 different ways:
    • trying to save the image when no permissions have been asked manually beforehand (NativeGallery will request write-only permission)
    • trying to save the image when RequestPermission(PermissionType.Write) returns LimitedAccess (PermissionFreeMode must be set to false to test this)
  • trying to call TryExtendLimitedAccessPermission function multiple times per session and seeing if it works
  • picking images & videos simultaneously using GetMixedMediasFromGallery with MediaType.Image | MediaType.Video argument

If you could test these features for me, I'd really appreciate it. I've written the following test script, you may find it useful:

// This must be assigned value from the Inspector
public Texture2D image;

private GUIStyle buttonStyle;
private int optionsUnlocked;

private void OnGUI()
{
	if( buttonStyle == null )
		buttonStyle = new GUIStyle( GUI.skin.button ) { fontSize = Screen.height / 40, wordWrap = true };

	float width = Screen.width;
	float height = Screen.height;
	if( optionsUnlocked == 0 )
	{
		if( GUI.Button( new Rect( 0f, 0f, width, height * 0.2f ), "See Buttons", buttonStyle ) )
		{
			optionsUnlocked = 1;
			Invoke( "UnlockOptions", 0.1f );
			GUIUtility.ExitGUI();
		}
	}
	else if( optionsUnlocked == 2 )
	{
		bool interacted = false;

		if( GUI.Button( new Rect( 0f, 0f, width / 3, height * 0.2f ), "Permission Free Mode: " + NativeGallery.PermissionFreeMode, buttonStyle ) )
			NativeGallery.PermissionFreeMode = !NativeGallery.PermissionFreeMode;
		if( GUI.Button( new Rect( width / 3, 0f, width / 3, height * 0.2f ), "Check Read Permission", buttonStyle ) )
			print( NativeGallery.CheckPermission( NativeGallery.PermissionType.Read ) );
		if( GUI.Button( new Rect( width * 2 / 3, 0f, width / 3, height * 0.2f ), "Check Write Permission", buttonStyle ) )
			print( NativeGallery.CheckPermission( NativeGallery.PermissionType.Write ) );

		if( GUI.Button( new Rect( 0f, height * 0.2f, width / 3, height * 0.2f ), "Request Read Permission", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.RequestPermission( NativeGallery.PermissionType.Read ) );
		}
		if( GUI.Button( new Rect( width / 3, height * 0.2f, width / 3, height * 0.2f ), "Request Write Permission", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.RequestPermission( NativeGallery.PermissionType.Write ) );
		}
		if( GUI.Button( new Rect( width * 2 / 3, height * 0.2f, width / 3, height * 0.2f ), "Extend Limited Permission", buttonStyle ) )
		{
			interacted = true;
			NativeGallery.TryExtendLimitedAccessPermission();
		}

		if( GUI.Button( new Rect( 0f, height * 0.4f, width / 3, height * 0.2f ), "Get Image", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetImageFromGallery( ( path ) =>
			{
				print( path );
				DisplayImage( path );
			} ) );
		}
		if( GUI.Button( new Rect( width / 3, height * 0.4f, width / 3, height * 0.2f ), "Get Video", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetVideoFromGallery( ( path ) =>
			{
				print( path );
				DisplayVideo( path );
			} ) );
		}
		if( GUI.Button( new Rect( width * 2 / 3, height * 0.4f, width / 3, height * 0.2f ), "Get Image/Video", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetMixedMediaFromGallery( ( path ) =>
			{
				print( path );
				if( path != null )
				{
					// Determine if user has picked an image, video or neither of these
					switch( NativeGallery.GetMediaTypeOfFile( path ) )
					{
						case NativeGallery.MediaType.Image: Debug.Log( "Picked image" ); break;
						case NativeGallery.MediaType.Video: Debug.Log( "Picked video" ); break;
						default: Debug.Log( "Probably picked something else" ); break;
					}
				}
			}, NativeGallery.MediaType.Image | NativeGallery.MediaType.Video ) );
		}

		if( GUI.Button( new Rect( 0f, height * 0.6f, width / 3, height * 0.2f ), "Get Images", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetImagesFromGallery( ( paths ) =>
			{
				if( paths != null )
				{
					for( int i = 0; i < paths.Length; i++ )
					{
						print( paths[i] );

						if( i == paths.Length - 1 )
							DisplayImage( paths[i] );
					}
				}
			} ) );
		}
		if( GUI.Button( new Rect( width / 3, height * 0.6f, width / 3, height * 0.2f ), "Get Videos", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetVideosFromGallery( ( paths ) =>
			{
				if( paths != null )
				{
					for( int i = 0; i < paths.Length; i++ )
					{
						print( paths[i] );

						if( i == paths.Length - 1 )
							DisplayVideo( paths[i] );
					}
				}
			} ) );
		}
		if( GUI.Button( new Rect( width * 2 / 3, height * 0.6f, width / 3, height * 0.2f ), "Get Images/Videos", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.GetMixedMediasFromGallery( ( paths ) =>
			{
				if( paths != null )
				{
					for( int i = 0; i < paths.Length; i++ )
					{
						print( paths[i] );

						// Determine if user has picked an image, video or neither of these
						switch( NativeGallery.GetMediaTypeOfFile( paths[i] ) )
						{
							case NativeGallery.MediaType.Image: Debug.Log( "Picked image" ); break;
							case NativeGallery.MediaType.Video: Debug.Log( "Picked video" ); break;
							default: Debug.Log( "Probably picked something else" ); break;
						}
					}
				}
			}, NativeGallery.MediaType.Image | NativeGallery.MediaType.Video ) );
		}

		if( GUI.Button( new Rect( 0f, height * 0.8f, width, height * 0.2f ), "Save Image", buttonStyle ) )
		{
			interacted = true;
			print( NativeGallery.SaveImageToGallery( image, "Test Album", "Hello world.png", ( bool success, string path ) =>
			{
				print( "Save result: " + success + " " + path );
			} ) );
		}

		if( interacted )
		{
			optionsUnlocked = 1;
			Invoke( "LockOptions", 0.1f );
			GUIUtility.ExitGUI();
		}
	}
}

private void DisplayImage( string path )
{
	if( path != null )
	{
		// Create Texture from selected image
		Texture2D texture = NativeGallery.LoadImageAtPath( path, 512 );
		if( texture == null )
		{
			Debug.Log( "Couldn't load texture from " + path );
			return;
		}

		// Assign texture to a temporary quad and destroy it after 5 seconds
		GameObject quad = GameObject.CreatePrimitive( PrimitiveType.Quad );
		quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
		quad.transform.forward = Camera.main.transform.forward;
		quad.transform.localScale = new Vector3( 1f, texture.height / (float) texture.width, 1f );

		Material material = quad.GetComponent<Renderer>().material;
		if( !material.shader.isSupported ) // happens when Standard shader is not included in the build
			material.shader = Shader.Find( "Legacy Shaders/Diffuse" );

		material.mainTexture = texture;

		Destroy( quad, 5f );
		Destroy( texture, 5f );
	}
}

private void DisplayVideo( string path )
{
	if( path != null )
		Handheld.PlayFullScreenMovie( "file://" + path ); // It is OK if this function sometimes fails due to "Couldn't attach movie player to UIImagePickerController"-like warnings
}

private void UnlockOptions()
{
	optionsUnlocked = 2;
}

private void LockOptions()
{
	optionsUnlocked = 0;
}

@BigGiantHead
Copy link

Has this been resolved? Is the fix released on the asset store?

@yasirkula
Copy link
Owner

I'll release the fix when it is confirmed to be working. You can check out the post above to download the latest version and test it on your iOS 14 devices.

@BigGiantHead
Copy link

Ok, thanks,

I'll test tomorrow once I install iOS 14 beta and Xcode beta.

@BigGiantHead
Copy link

@yasirkula I am testing at the moment. The read works great, I can pick images and videos.

The write permission I am still not sure of.
In my app I need to save a video in gallery.
I am actually getting 2 permission windows in a row when I ask for write permission.
The first one says "The app requires access to Photos to save media to it".
After that I immediately get another permission window The app requires access to Photos to interact with it.

My app needs only the write access, it doesn't need to access to files without user selection.

@BigGiantHead
Copy link

@yasirkula also when the write permission is granted the app returns the permission immediately, not after the second permission window closes.

@yasirkula
Copy link
Owner

Hmm, I fear that the second permission is asked by the OS when I try to save the video to a specific album. I'm guessing that the second permission dialog had 3 options: Allow, Select Photos and Deny, am I right?

@BigGiantHead
Copy link

@yasirkula yes exactly. Is there a way to only save without a specific album?

@yasirkula
Copy link
Owner

yasirkula commented Sep 15, 2020

Yes, inside NativeGallery.mm file, delete lines [405, 466] and put a single saveToPhotosAlbum(); statement there instead.

To resolve this issue in general, I think I'll support 2 different use-cases:

  1. When PermissionFreeMode is set to true, I'll show the "The app requires access to Photos to save media to it." permission dialog and ignore the album parameter
  2. When PermissionFreeMode is set to false, I'll show the "The app requires access to Photos to interact with it." permission dialog and if user grants full permission, I'll save to the specified album. Otherwise, I'll ignore the album parameter. Full permission is needed for custom albums on iOS 14, unfortunately. There are 2 forum threads on Apple's website about this issue:

@BigGiantHead
Copy link

@yasirkula thank you for the solution, but the lines you told me about don't seem to correspond to the file I have.
Can you give me a modified .mm file? You can see on the screenshot below what I mean.

Screen Shot 2020-09-16 at 11 21 22

@BigGiantHead
Copy link

@yasirkula I am also getting the following error when I only have read permission:

Screen Shot 2020-09-16 at 13 30 06

@yasirkula
Copy link
Owner

In your case, you can delete lines [413,474] and insert saveToPhotosAlbum(); at line 413.

The "you don't have permission to view it" warning is normal when you grant "Selected photos" permission but pick a photo that wasn't included in "Selected photos". This should happen only when PermissionFreeMode is set to false. This warning message is harmless so you can safely ignore it in either case (I'm assuming that the picked image was loaded successfully in Unity).

@BigGiantHead
Copy link

BigGiantHead commented Sep 16, 2020

@yasirkula thanks very much, just checked and the fix is working fine.

@aengmo1
Copy link

aengmo1 commented Sep 16, 2020

@yasirkula Do you have a time estimate on when your fix is ready? :)

@yasirkula
Copy link
Owner

@aengmo1 I need to verify that the use-cases I've mentioned in this comment are all working properly. Unity doesn't support iOS 14 simulators and I don't have an iOS 14 device, so I can't verify them at the moment.

@MaryamSaeed
Copy link
Author

MaryamSaeed commented Sep 20, 2020

@yasirkula so sorry for may late reply and thank you for the updates,
till now i've tested the photos permission so here is the scenario i run unity example>> take an image >> attempt t save for the first time >> select "selected Photos">> image does not get saved , restart unity, take an image >> attempt to save for the second time >> image gets saved !!,
this is the behavior i get now , i will update you with the behavior of all the test cases and i will debug this behavior more.

@yasirkula
Copy link
Owner

@MaryamSaeed Hmm, did this happen after updating the plugin using the download link I've provided? Were there any error messages in Xcode console?

@MaryamSaeed
Copy link
Author

MaryamSaeed commented Sep 22, 2020

@yasirkula yes ,i am setting up Xcode 12 and will check what message i get from the console
Update 24/9/2020,
var perm = NativeGallery.SaveImageToGallery(tex, "CustomAlbum", fileName); if (perm == NativeGallery.Permission.Granted) ImageSaved.Invoke(); else if (perm == NativeGallery.Permission.Denied || perm == NativeGallery.Permission.LimitedAccess) OpenSettings.Invoke();

when i open the app and attempt to save for the first time a prompt appears and and ask to add photos giving 2 options allow and deny , when i allow photos the image gets saved in recents,
when i close the app i change the permission from settings to selected photos and attempts to save again the image gets saved and the code in else above not called.

@dtaddisF42
Copy link

@yasirkula Thank you for the recent updates... we just needed write-only access and it's made the iOS 14 permissions prompt nice and tidy now.

@yasirkula
Copy link
Owner

@dtaddisF42 Yes, the write-only permission dialog is definitely more user friendly than the one with "Select Photos" option. The only downside is that the custom album name will be ignored. I hope Apple allows us to save media to custom albums with write-only permission 🤞

@MaryamSaeed
Copy link
Author

MaryamSaeed commented Sep 24, 2020

@yasirkula Okay i am running your test cases now,
The features you wanted to test on iOS 14 are:

  • picking multiple images/videos : working fine i was able to pick multiple videos and images ☑️
  • picking live photos and checking if the returned image can be loaded with LoadImageAtPath without any issues (including orientation issues)(it won't be animated but that's expected): i was able to pick a live image but its opened as a black image on screen afterwards.
  • picking gif images in PermissionFreeMode and seeing if the returned path points to a .gif image (preferred) or a .png image:

Screen Shot 2020-09-24 at 10 20 51 AM

saving an image to Photos when full Photos access isn't granted (I suspect that the image will be saved to the default Camera Roll album instead of the custom album in this case). This must be tested in 2 different ways:

  • trying to save the image when no permissions have been asked manually beforehand (NativeGallery will request write-only permission)==> you were right it got saved in the recents and here is the logs , but when i set the free mode to false and i got asked for photos permission and i select all photos it gets saved to the test album.

Screen Shot 2020-09-24 at 10 31 22 AM

  • trying to save the image when RequestPermission(PermissionType.Write) returns LimitedAccess (PermissionFreeMode must be set to false to test this) ==> the mobile hangs and nothing appears in the logs after the following and didn't save the image, had to restart the app and i tried to save the image but it didn't save the image.

Screen Shot 2020-09-24 at 10 42 40 AM

  • trying to call TryExtendLimitedAccessPermission function multiple times per session and seeing if it works : when i pressed Extend Limited Permission a prompt asks for photos permission with the three options (select photos , allow access to all photos and Dont allow) nothing appears in the logs 😟 , i selected select photos and the Mobile hangs again nothing appears in the logs.
  • picking images & videos simultaneously using GetMixedMediasFromGallery with MediaType.Image | MediaType.Video argument.
    i pressed get images/Videos and selected 2 images and 2 videos and here are the logs,

Screen Shot 2020-09-24 at 11 21 35 AM

Screen Shot 2020-09-24 at 11 22 28 AM

there are 2 features i did not test yet

Update
this is how the app settings looks like for the test cases,

yasirtest

@yasirkula
Copy link
Owner

Thank you for testing these features, your help is much appreciated. I see that half of the features don't work at all... I'll have to wait until Unity adding support for iOS 14 simulators so that I can debug these issues in detail :/ Until then, I won't release this iOS 14 update.

@MaryamSaeed
Copy link
Author

@yasirkula glad i could help 😄 ,
i guess the media picking is working fine for videos and images and single video and single image and the write permission is working fine too most images got saved in recents and i told you above about the "testalbum" case , you can have a look at my updated comment above too i added something related to the selected photo option

@yasirkula
Copy link
Owner

As far as I understand, trying to write to Photos with "Select Photos" permission freezes the device with a "Saving non-readable textures is slower" log. That log is normal but the freeze isn't. At the moment, I'm unsure about the cause of the freeze. I'll get to the bottom of it when iOS 14 simulators are supported :D

@MaryamSaeed
Copy link
Author

MaryamSaeed commented Sep 24, 2020

@yasirkula check this out ,
i rebuild the unity project and ran it again and i can't see the "selected photos option" in the app permissions ,
guess its working now 👍 ,
MicrosoftTeams-image

@yasirkula
Copy link
Owner

But why would it freeze when you first tested it? TryExtendLimitedAccessPermission freezing is also a similar issue.

@MaryamSaeed
Copy link
Author

the above image is for the example i am testing on,
while for the test cases i see the full options in the photos screen,
let me update the comment of the test cases above with the image

@yasirkula
Copy link
Owner

It looks like these screenshots are taken from the app's permission settings in Settings app. I think that as long as the permission dialog with "Select Photos" option isn't displayed (i.e. when app is in PermissionFreeMode), only the "Add Photos Only" permission will be listed in Settings. After displaying the permission dialog with "Select Photos" option, Settings will expand to include all 3 options.

But still, this isn't related to the freeze problem, am I right?

@MaryamSaeed
Copy link
Author

MaryamSaeed commented Sep 24, 2020

let me test this scenario and get back to you
Update :

  • scenario 1 > run app for the first time > save image > open settings app >testcases photos permissions > 2 Options (add photos only & none)
    now i get back to the app and set free mode to false
  • scenario 2> extend limited Permission> prompt appear with three options (select photos, allow access to all photos , dont allow)> select photos> mobile hangs > open settings app > testcases photos permissions > 4 options displayed (add photos only, selected photos,All photos,None)
  • scenario 3 > run app for the first time> set free mode to false > save image > prompt appear with three options (select photos, allow access to all photos , dont allow)> allow access to all photos >open settings app > testcases photos permissions > 3 options displayed (selected photos,All photos,None)

@Saicopate
Copy link

I am also having issues with permission handling in iOS 14.
Using the plugin for getting pictures from gallery and saving screenshots.

When application is first launched it asks for permissions on either of the above events.
When selecting "Choose pictures.." instead of "Give access to whole gallery" the app hangs, as if it remains in suspended state. No gallery pop-up window. No error codes in the console.

When the app is manually closed and restarted it no longer asks for permissions and seems to work ok.
Any solutions for the time being?

@yasirkula
Copy link
Owner

Does the app still freeze when you comment out the dispatch_semaphore_wait( sema, DISPATCH_TIME_FOREVER ); line from requestPermissionNewest in NativeGallery.mm? It will return wrong permission result but at least we can see if that line is causing this issue.

@Saicopate
Copy link

After commenting this line in two places a new window comes out to select pictures that will be available for the app. Confirmimg this window stops the process. The app now seems to be alive but the gallery selection windows does not appear. Need to restart the app to work.

@yasirkula
Copy link
Owner

Do you also encounter the freeze issue that occurs after calling TryExtendLimitedAccessPermission and selecting "Select Photos"?

@Saicopate
Copy link

Now I noticed your post above with beta version of Native Gallery. Uploaded it to the project and now it seems to work fine.
Sorry for bothering ;-) and thanks for keeping it going :-)

@GITHUB243884919
Copy link

Hi, I used master and appstore told me app can not save picture in IOS14.1.
I watch above you discussed, I want know should I download “https://github.com/yasirkula/UnityNativeGallery/files/5241555/NativeGallery.zip” to solve problem?
Thank you very much.

@GITHUB243884919
Copy link

GITHUB243884919 commented Sep 28, 2020

Now I noticed your post above with beta version of Native Gallery. Uploaded it to the project and now it seems to work fine.
Sorry for bothering ;-) and thanks for keeping it going :-)
As you say, download from “https://github.com/yasirkula/UnityNativeGallery/files/5241555/NativeGallery.zip” ,is all right?
thank you

@yasirkula
Copy link
Owner

If you don't touch the value of NativeGallery.PermissionFreeMode, then you should be good to go. The only downside is that, your images will be saved to default Photos album rather than the one you've passed as parameter.

@GITHUB243884919
Copy link

If you don't touch the value of NativeGallery.PermissionFreeMode, then you should be good to go. The only downside is that, your images will be saved to default Photos album rather than the one you've passed as parameter.
Thank for you reply~
You mean is :If I use master then I could save photo to default Photos album? Or I should use “https://github.com/yasirkula/UnityNativeGallery/files/5241555/NativeGallery.zip”

@yasirkula
Copy link
Owner

You should use the zip archive, yes.

@GITHUB243884919
Copy link

You should use the zip archive, yes.

Thank you again~

@GITHUB243884919
Copy link

You should use the zip archive, yes.

Thank you very much!It can save to default album~

@yasirkula
Copy link
Owner

With the latest release, I removed the PermissionFreeMode property (set it to always true). Also removed the LimitedAccess permission (treated it as Granted) since in PermissionFreeMode, the "Select Photos" permission isn't displayed at all. This way, the current API stayed pretty much the same.

The only downside is that, photos/videos will be saved to the default Photos album instead of the specified custom album on iOS 14+. To be able to save media to a custom album, we must show the "Allow Access", "Select Photos", "Deny" permission dialog and the user must select the "Allow Access" option. Clicking "Select Photos" freezes the app (I think due to how I handle the permission dialog synchronously) and even if it didn't freeze, it is a weird user experience to see "Select Photos" option while attempting to save an image to Photos.

@CUTEQWQ
Copy link

CUTEQWQ commented Apr 2, 2021

With the latest release, I removed the PermissionFreeMode property (set it to always true). Also removed the LimitedAccess permission (treated it as Granted) since in PermissionFreeMode, the "Select Photos" permission isn't displayed at all. This way, the current API stayed pretty much the same.

The only downside is that, photos/videos will be saved to the default Photos album instead of the specified custom album on iOS 14+. To be able to save media to a custom album, we must show the "Allow Access", "Select Photos", "Deny" permission dialog and the user must select the "Allow Access" option. Clicking "Select Photos" freezes the app (I think due to how I handle the permission dialog synchronously) and even if it didn't freeze, it is a weird user experience to see "Select Photos" option while attempting to save an image to Photos.

If I want to show the "Select photos" Option, but after iOS11+, the permission is always allowed.
Can I set the PermissionFreeMode property to false? I Find the document says it will crash the game, so how to figure it ?

@yasirkula
Copy link
Owner

Why would you want to show "Select Photos" permission option?

@CUTEQWQ
Copy link

CUTEQWQ commented Apr 2, 2021

I want user to manage his gallery permission..

@yasirkula
Copy link
Owner

I still don't get it, sorry. You don't need any permissions to get media from Photos on iOS11+ and you need to show only an "Allow/Deny" permission to save media to Photos. "Select Photos" permission is completely redundant. Why would you want to show a permission option that does basically nothing in NativeGallery?

@CUTEQWQ
Copy link

CUTEQWQ commented Apr 2, 2021

Because maybe a user doesn't want the game to access some photos in the gallery, though on iOS11+ we can access all permission. I think that's the reason why iOS14 push the new permission solution. So I want to show "Select Photos" option, that they can manage their own gallery permission.

@yasirkula
Copy link
Owner

yasirkula commented Apr 2, 2021

I see your point but Select Photos doesn't work like that. PHPickerViewController will always show the whole album regardless of Select Photos. That is internal design by iOS team and it is a good thing because: 1) seeing all photos in PHPickerViewController doesn't mean that app has instant access to these photos, app has access to only the picked photos because otherwise it would be a ridiculous privacy issue and 2) as I said, we don't need any permissions.

Select Photos permission is used only to fetch sensitive metadata from picked images or access those selected photos programmatically without needing to present the image picker (PHPickerViewController). I'd recommend you to google "select photos shows all gallery PHPickerViewController" and "ios 14 PHPickerViewController" for more info.

@Archi97
Copy link

Archi97 commented Apr 29, 2021

Hello. Im using this version to fix iOS crash. but not it is crashing on android.
What should i do.
I have set Write permision to External. but it didnt help me.
Thanks.

@MaryamSaeed I've added the following features to the plugin:

  • switched to PHPickerViewController on iOS 14+, adding the ability to pick multiple images/videos on iOS 14+
  • iOS 14 permissions support: added LimitedAccess to Permission enum
  • added NativeGallery.PermissionFreeMode boolean: when it is set to true, picking media from Photos will not require any permissions on iOS 11+ but the metadata of the picked media may not always be retrieved
  • CheckPermission and RequestPermission functions now take either PermissionType.Read or PermissionType.Write argument
  • When Permission is LimitedAccess, TryExtendLimitedAccessPermission can be called to prompt the user to extend their limited selection
  • Live photos can now be selected while picking images

UPDATE (09/17): on iOS 14, when PermissionFreeMode is set to true, SaveImageToGallery/SaveVideoToGallery will ignore the album parameter: #136 (comment)

Download: https://github.com/yasirkula/UnityNativeGallery/files/5241555/NativeGallery.zip

@yasirkula
Copy link
Owner

You should check logcat logs to find the crash logs, check if an Issue has already been created for that error and if not, create a new Issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants