在Unity iOS上打开设置应用程序 [英] Open Settings application on Unity iOS
问题描述
我需要一种使用户进入设置"应用程序以禁用多任务手势的方法.我知道在iOS 8中,您可以通过Objective-C中的URL以编程方式启动设置"应用程序:
I am in need of a way to make the user is taken to the Settings application to disable the multitasking gestures. I know that in iOS 8 you can launch the Settings application programmatically through the URL in Objective-C:
NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
但是我不知道如何在Unity中获取此URL以与Application.OpenURL()一起使用
But I do not know how to get this URL in Unity to use with Application.OpenURL()
推荐答案
You need to write a tiny iOS plugin for that, here is more information about it: http://docs.unity3d.com/Manual/PluginsForIOS.html
这是您的解决方案,请问是否应该不清楚.
And here is your solution, ask if something should be unclear.
脚本/示例.cs
using UnityEngine;
public class Example
{
public void OpenSettings()
{
#if UNITY_IPHONE
string url = MyNativeBindings.GetSettingsURL();
Debug.Log("the settings url is:" + url);
Application.OpenURL(url);
#endif
}
}
插件/MyNativeBindings.cs
public class MyNativeBindings
{
#if UNITY_IPHONE
[DllImport ("__Internal")]
public static extern string GetSettingsURL();
[DllImport ("__Internal")]
public static extern void OpenSettings();
#endif
}
插件/iOS/MyNativeBindings.mm
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);
}
void OpenSettings () {
NSURL * url = [NSURL URLWithString: UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL: url];
}
}
这篇关于在Unity iOS上打开设置应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!