Request native iOS camera permissions and get a callback method in Unity.
Download the latest ios_camera_permission.unitypackage
file from the Release page, drag and drop it in your project folder and click import.
- You must set a Camera Usage Description in the Player Settings.
If you want to ask camera permission and display the native iOS popup, call AskPermission()
.
The method signature is AskPermission(string gameObjectName, string callbackName)
where gameObjectName
is the name of the game object that will receive the callback via the Unity's build-in SendMessage()
method. callbackName
is the name of the method to call on the gameObject.
Note: It is recommended to use
nameof(MyMethod)
in thecallbackName
parameter to avoid errors when renaming or changing the callbacks.
public void AskPermission()
{
iOSCameraPermission.AskPermission(gameObject.name, nameof(AskCallback));
}
void AskCallback(string permissionWasGranted)
{
// permissionWasGranted will either be "true" or "false".
}
If you just want to verify the current permission for your app (useful to avoid asking when the permission is already granted), you can call VerifyPermision()
. The method signature and callbacks are the same as AskPermission()
.
public void VerifyPermission()
{
iOSCameraPermission.VerifyPermission(gameObject.name, nameof(VerifyCallback));
}
void VerifyCallback(string authorizationStatus)
{
// authorizationStatus will be one of the following:
// - Authorized
// - Denied
// - NotDetermined
// - Restricted
}
All .h and .m files must be in the follow location:
[ProjectName]/Assets/Plugins/iOS
See Assets/iOSCameraPermission/Samples/SampleScene.unity
Each one of the two buttons in the scene has a UsageSample
component and its OnClick()
callback set to one of the two available methods.
Camera Usage Description is set to "Sample Camera Usage Description"