From eb8200fdc1c83b362f7d732a454aade9d127b6f2 Mon Sep 17 00:00:00 2001 From: thiago.filipe Date: Tue, 4 Apr 2017 10:35:35 -0300 Subject: [PATCH] Fix IOS permission --- Assets/Scripts/Export Video/ExportVideo.cs | 23 ++++++++++++++--------- Assets/Scripts/Export Video/ShareIOS.cs | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 11 deletions(-) diff --git a/Assets/Scripts/Export Video/ExportVideo.cs b/Assets/Scripts/Export Video/ExportVideo.cs index 7fc5a8f..98dc6af 100644 --- a/Assets/Scripts/Export Video/ExportVideo.cs +++ b/Assets/Scripts/Export Video/ExportVideo.cs @@ -82,23 +82,23 @@ public class ExportVideo : MonoBehaviour { private void onClickExport() { PlayerLogger.Log("ExportVideo", "OnClickExport", "Starting Export..."); - export(); + ShareIOS.AskForPermission(Permitted); } - private void export() + private void Permitted(bool PermissionGranted) { - int fiveTimesCount; - - /* Making the app shows the dialog for the user every five times.*/ + if (PermissionGranted) + { + int fiveTimesCount; if (PlayerPrefs.HasKey("fiveTimesCount")) { fiveTimesCount = PlayerPrefs.GetInt("fiveTimesCount"); - if(fiveTimesCount < 5) + if (fiveTimesCount < 5) { fiveTimesCount++; PlayerPrefs.SetInt("fiveTimesCount", fiveTimesCount); @@ -112,7 +112,8 @@ public class ExportVideo : MonoBehaviour { PlayerPrefs.Save(); } - }else + } + else { PlayerPrefs.SetFloat("fiveTimesCount", 0); PlayerPrefs.Save(); @@ -137,8 +138,12 @@ public class ExportVideo : MonoBehaviour { startExport(); } - - + } + else + { + screenManager.showPermissionDialog("Para salvar e compartilhar as animações, permita que o Vlibras acesse mídia e arquivos de seu aparelho.", "Exportar Vìdeo"); + + } } diff --git a/Assets/Scripts/Export Video/ShareIOS.cs b/Assets/Scripts/Export Video/ShareIOS.cs index 6d97a02..2620cb3 100644 --- a/Assets/Scripts/Export Video/ShareIOS.cs +++ b/Assets/Scripts/Export Video/ShareIOS.cs @@ -2,14 +2,40 @@ using System.Collections; using System.Runtime.InteropServices; using System.IO; +using System; + /* * https://github.com/ChrisMaire/unity-native-sharing */ public class ShareIOS : MonoBehaviour { + private static ShareIOS instance; + + private static Action PermittedAction; + private static bool initialized = false; + + public void Awake() + { + instance = this; + DontDestroyOnLoad(this.gameObject); + + } + + + private static void initialize() + { + + if(instance == null) + { + GameObject go = new GameObject(); + instance = go.AddComponent(); + go.name = "ShareIOS"; + } + initialized = true; + } - public void Share(string shareText, string imagePath, string url, string subject) + public void Share(string shareText, string imagePath, string url, string subject) { #if UNITY_IOS CallSocialShareAdvanced(shareText, subject, url, imagePath); @@ -67,5 +93,37 @@ public class ShareIOS : MonoBehaviour { } - #endif + [DllImport("__Internal")] private static extern void askForPermission(ref ConfigStruct conf); + + public static void AskForPermission(Action CallBack) + { + if (!initialized) + initialize(); + PermittedAction = CallBack; + ConfigStruct conf = new ConfigStruct(); + conf.title = "ShareIOS"; + conf.message = "ResponseFromIOS"; + askForPermission(ref conf); + } + + private void ResponseFromIOS(string response) + { + if (PermittedAction != null) + { + if (response == "PERMITIDO") + { + PermittedAction(true); + } + else + { + PermittedAction(false); + } + + } + PermittedAction = null; + + + } + +#endif } -- libgit2 0.21.2