-
-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added async variants of RequestPermission function that don't freeze …
…the app unnecessarily
- Loading branch information
Showing
10 changed files
with
232 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
= Native Gallery for Android & iOS (v1.7.3) = | ||
= Native Gallery for Android & iOS (v1.7.4) = | ||
|
||
Online documentation & example code available at: https://github.com/yasirkula/UnityNativeGallery | ||
E-mail: [email protected] | ||
|
@@ -57,6 +57,7 @@ enum NativeGallery.Permission { Denied = 0, Granted = 1, ShouldAsk = 2 }; | |
enum NativeGallery.ImageOrientation { Unknown = -1, Normal = 0, Rotate90 = 1, Rotate180 = 2, Rotate270 = 3, FlipHorizontal = 4, Transpose = 5, FlipVertical = 6, Transverse = 7 }; // EXIF orientation: http://sylvana.net/jpegcrop/exif_orientation.html (indices are reordered) | ||
enum MediaType { Image = 1, Video = 2, Audio = 4 }; | ||
|
||
delegate void PermissionCallback( NativeGallery.Permission permission ); | ||
delegate void MediaSaveCallback( bool success, string path ); | ||
delegate void NativeGallery.MediaPickCallback( string path ); | ||
delegate void MediaPickMultipleCallback( string[] paths ); | ||
|
@@ -113,6 +114,10 @@ bool NativeGallery.IsMediaPickerBusy(); | |
NativeGallery.Permission NativeGallery.CheckPermission( PermissionType permissionType, MediaType mediaTypes ); | ||
NativeGallery.Permission NativeGallery.RequestPermission( PermissionType permissionType, MediaType mediaTypes ); | ||
|
||
// Asynchronous variants of RequestPermission. Unlike RequestPermission, these functions don't freeze the app unnecessarily before the permission dialog is displayed. So it's recommended to call these functions instead | ||
void NativeGallery.RequestPermissionAsync( PermissionCallback callback, PermissionType permissionType, MediaType mediaTypes ); | ||
Task<NativeGallery.Permission> NativeGallery.RequestPermissionAsync( PermissionType permissionType, MediaType mediaTypes ); | ||
|
||
// If permission state is Permission.Denied, user must grant the necessary permission (Storage on Android and Photos on iOS) manually from the Settings. These functions help you open the Settings directly from within the app | ||
void NativeGallery.OpenSettings(); | ||
bool NativeGallery.CanOpenSettings(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#if UNITY_EDITOR || UNITY_IOS | ||
using UnityEngine; | ||
|
||
namespace NativeGalleryNamespace | ||
{ | ||
public class NGPermissionCallbackiOS : MonoBehaviour | ||
{ | ||
private static NGPermissionCallbackiOS instance; | ||
private NativeGallery.PermissionCallback callback; | ||
|
||
public static void Initialize( NativeGallery.PermissionCallback callback ) | ||
{ | ||
if( instance == null ) | ||
{ | ||
instance = new GameObject( "NGPermissionCallbackiOS" ).AddComponent<NGPermissionCallbackiOS>(); | ||
DontDestroyOnLoad( instance.gameObject ); | ||
} | ||
else if( instance.callback != null ) | ||
instance.callback( NativeGallery.Permission.ShouldAsk ); | ||
|
||
instance.callback = callback; | ||
} | ||
|
||
public void OnPermissionRequested( string message ) | ||
{ | ||
NativeGallery.PermissionCallback _callback = callback; | ||
callback = null; | ||
|
||
if( _callback != null ) | ||
_callback( (NativeGallery.Permission) int.Parse( message ) ); | ||
} | ||
} | ||
} | ||
#endif |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.