-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
157 additions
and
38 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 Camera for Android & iOS (v1.3.9) = | ||
= Native Camera for Android & iOS (v1.4.0) = | ||
|
||
Online documentation & example code available at: https://github.com/yasirkula/UnityNativeCamera | ||
E-mail: [email protected] | ||
|
@@ -38,6 +38,7 @@ enum NativeCamera.Permission { Denied = 0, Granted = 1, ShouldAsk = 2 }; | |
enum NativeCamera.Quality { Default = -1, Low = 0, Medium = 1, High = 2 }; | ||
enum NativeCamera.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) | ||
|
||
delegate void PermissionCallback( NativeCamera.Permission permission ); | ||
delegate void CameraCallback( string path ); | ||
|
||
//// Accessing Camera //// | ||
|
@@ -66,6 +67,10 @@ bool NativeCamera.IsCameraBusy(); // returns true if the camera is currently ope | |
NativeCamera.Permission NativeCamera.CheckPermission( bool isPicturePermission ); | ||
NativeCamera.Permission NativeCamera.RequestPermission( bool isPicturePermission ); | ||
|
||
// 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 NativeCamera.RequestPermissionAsync( PermissionCallback callback, PermissionType permissionType, MediaType mediaTypes ); | ||
Task<NativeCamera.Permission> NativeCamera.RequestPermissionAsync( PermissionType permissionType, MediaType mediaTypes ); | ||
|
||
// If permission state is Permission.Denied, user must grant the necessary permission(s) manually from the Settings (Android requires Storage and, if declared in AndroidManifest, Camera permissions; iOS requires Camera permission). These functions help you open the Settings directly from within the app | ||
void NativeCamera.OpenSettings(); | ||
bool NativeCamera.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 NativeCameraNamespace | ||
{ | ||
public class NCPermissionCallbackiOS : MonoBehaviour | ||
{ | ||
private static NCPermissionCallbackiOS instance; | ||
private NativeCamera.PermissionCallback callback; | ||
|
||
public static void Initialize( NativeCamera.PermissionCallback callback ) | ||
{ | ||
if( instance == null ) | ||
{ | ||
instance = new GameObject( "NCPermissionCallbackiOS" ).AddComponent<NCPermissionCallbackiOS>(); | ||
DontDestroyOnLoad( instance.gameObject ); | ||
} | ||
else if( instance.callback != null ) | ||
instance.callback( NativeCamera.Permission.ShouldAsk ); | ||
|
||
instance.callback = callback; | ||
} | ||
|
||
public void OnPermissionRequested( string message ) | ||
{ | ||
NativeCamera.PermissionCallback _callback = callback; | ||
callback = null; | ||
|
||
if( _callback != null ) | ||
_callback( (NativeCamera.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.
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