728x90
728x90
SMALL
유니티에서 아이폰 앱을 개발하다보면 처음에 권한을 얻어야하는 기능들이 많다.
허나 처음에 권한을 얻지 못하면 다시 요청 창을 띄울 수 없기에
사용자가 직접 앱 설정 화면으로 들어가 권한을 승인해주어야한다.
이때 바로 앱 설정 화면으로 진입할 수 있도록 하는 plugin 코드를 작성해보았다.
아래 코드들은 스택플로우의 사이트에서 참고한 것인데...
사이트 링크를 잃어버렸다.......ㅜㅜ
Script
- IOSSetting.cs
public class IOSSetting : MonoBehaviour
{
#if UNITY_IOS
[DllImport("__Internal")]
public static extern string GetSettingsURL();
#endif
}
- IOSSetting.mm (Object-C)
extern "C" {
// Helper method to create C string copy
char* MakeStringCopy (NSString* nsstring)
{
if (nsstring == NULL) {
return NULL;
}
// convert from NSString to char with utf8 encoding
const char* string = [nsstring cStringUsingEncoding:NSUTF8StringEncoding];
if (string == NULL) {
return NULL;
}
// create char copy with malloc and strcpy
char* res = (char*)malloc(strlen(string) + 1);
strcpy(res, string);
return res;
}
const char* GetSettingsURL () {
NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
return MakeStringCopy(url.absoluteString);
}
}
- 사용 방법
string url = IOSSetting.GetSettingsURL();
Application.OpenURL(url);
- 프로젝트에 추가
1. cs 파일위치
프로젝트 폴더 > Assets > Plugins
2. .mm 파일 위치
프로젝트 폴더 > Assets > Plugins > IOS
.cs 파일에 명시한 GetSettingsURL() 함수를 사용하면 해당 앱 설정 URL을 가져온다.
이후 Application.OpenURL() 함수를 통해 URL로 이동하면 된다!
728x90
728x90
LIST