Are you an LLM? You can read better optimized documentation at /unity/sdk/api-permission.md for this page in Markdown format
권한 설정
클립보드, 위치 정보, 사진첩, 연락처 등의 기능을 사용하려면 권한을 설정해야 해요. 토스앱에서 이러한 기능들을 사용할 수 있도록 권한을 관리하는 API예요.
권한 목록
| 권한 이름 | 권한 키 | 접근 | 관련 API |
|---|---|---|---|
| 클립보드 | clipboard | 읽기(read), 쓰기(write) | GetClipboardText, SetClipboardText |
| 연락처 | contacts | 읽기(read) | FetchContacts |
| 사진첩 | photos | 읽기(read) | FetchAlbumPhotos |
| 카메라 | camera | 접근(access) | OpenCamera |
| 위치 | geolocation | 접근(access) | StartUpdateLocation, GetCurrentLocation |
API
| API | 반환 타입 | 설명 |
|---|---|---|
AIT.GetPermission() | PermissionStatus | 권한 상태를 조회해요 |
AIT.RequestPermission() | string | 권한을 요청해요 |
AIT.OpenPermissionDialog() | string | 권한 설정 다이얼로그를 열어요 |
권한 상태
| 상태 | 설명 |
|---|---|
allowed | 권한이 허용된 상태 |
denied | 권한이 거부된 상태 |
notDetermined | 아직 권한 요청을 하지 않은 상태 |
GetPermission
권한의 현재 상태를 조회해요.
csharp
try
{
var status = await AIT.GetPermission(new GetPermissionPermission());
Debug.Log($"권한 상태: {status}");
}
catch (AITException ex)
{
Debug.LogError($"권한 조회 실패: {ex.Message}");
}RequestPermission
사용자에게 권한을 요청해요. allowed 또는 denied를 반환해요.
csharp
try
{
string result = await AIT.RequestPermission(new RequestPermissionPermission());
if (result == "allowed")
{
Debug.Log("권한 허용됨");
}
else
{
Debug.Log("권한 거부됨");
}
}
catch (AITException ex)
{
Debug.LogError($"권한 요청 실패: {ex.Message}");
}OpenPermissionDialog
권한 설정 다이얼로그를 열어요. 이미 denied 상태인 경우 설정 화면으로 안내할 때 사용해요.
csharp
try
{
string result = await AIT.OpenPermissionDialog(new OpenPermissionDialogPermission());
Debug.Log($"권한 결과: {result}");
}
catch (AITException ex)
{
Debug.LogError($"권한 다이얼로그 실패: {ex.Message}");
}권한 플로우 예제
권한을 확인하고 기능을 사용하는 전체 플로우 예제예요.
csharp
using AppsInToss;
using UnityEngine;
public class PermissionExample : MonoBehaviour
{
async void Start()
{
try
{
// 1. 권한 상태 확인
var status = await AIT.GetPermission(new GetPermissionPermission());
if (status.ToString() == "notDetermined")
{
// 2. 권한 요청
string result = await AIT.RequestPermission(new RequestPermissionPermission());
if (result != "allowed") return;
}
else if (status.ToString() == "denied")
{
// 3. 설정 화면으로 안내
await AIT.OpenPermissionDialog(new OpenPermissionDialogPermission());
return;
}
// 4. 권한이 허용된 상태에서 기능 사용
var location = await AIT.GetCurrentLocation(new GetCurrentLocationOptions());
Debug.Log($"현재 위치: {location.Latitude}, {location.Longitude}");
}
catch (AITException ex)
{
Debug.LogError($"실패: {ex.Message}");
}
}
}TIP
- 권한이 필요한 API를 호출하기 전에 반드시 권한 상태를 확인하고 요청해 주세요.
denied상태에서는RequestPermission이 아닌OpenPermissionDialog로 설정 화면을 안내해 주세요.