Commit eb8200fdc1c83b362f7d732a454aade9d127b6f2
1 parent
6ff022a3
Exists in
IosBuild
Fix IOS permission
Showing
2 changed files
with
74 additions
and
11 deletions
Show diff stats
Assets/Scripts/Export Video/ExportVideo.cs
| @@ -82,23 +82,23 @@ public class ExportVideo : MonoBehaviour { | @@ -82,23 +82,23 @@ public class ExportVideo : MonoBehaviour { | ||
| 82 | private void onClickExport() | 82 | private void onClickExport() |
| 83 | { | 83 | { |
| 84 | PlayerLogger.Log("ExportVideo", "OnClickExport", "Starting Export..."); | 84 | PlayerLogger.Log("ExportVideo", "OnClickExport", "Starting Export..."); |
| 85 | - export(); | 85 | + ShareIOS.AskForPermission(Permitted); |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | - private void export() | 92 | + private void Permitted(bool PermissionGranted) |
| 93 | { | 93 | { |
| 94 | - int fiveTimesCount; | ||
| 95 | - | ||
| 96 | - /* Making the app shows the dialog for the user every five times.*/ | 94 | + if (PermissionGranted) |
| 95 | + { | ||
| 96 | + int fiveTimesCount; | ||
| 97 | 97 | ||
| 98 | if (PlayerPrefs.HasKey("fiveTimesCount")) | 98 | if (PlayerPrefs.HasKey("fiveTimesCount")) |
| 99 | { | 99 | { |
| 100 | fiveTimesCount = PlayerPrefs.GetInt("fiveTimesCount"); | 100 | fiveTimesCount = PlayerPrefs.GetInt("fiveTimesCount"); |
| 101 | - if(fiveTimesCount < 5) | 101 | + if (fiveTimesCount < 5) |
| 102 | { | 102 | { |
| 103 | fiveTimesCount++; | 103 | fiveTimesCount++; |
| 104 | PlayerPrefs.SetInt("fiveTimesCount", fiveTimesCount); | 104 | PlayerPrefs.SetInt("fiveTimesCount", fiveTimesCount); |
| @@ -112,7 +112,8 @@ public class ExportVideo : MonoBehaviour { | @@ -112,7 +112,8 @@ public class ExportVideo : MonoBehaviour { | ||
| 112 | PlayerPrefs.Save(); | 112 | PlayerPrefs.Save(); |
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | - }else | 115 | + } |
| 116 | + else | ||
| 116 | { | 117 | { |
| 117 | PlayerPrefs.SetFloat("fiveTimesCount", 0); | 118 | PlayerPrefs.SetFloat("fiveTimesCount", 0); |
| 118 | PlayerPrefs.Save(); | 119 | PlayerPrefs.Save(); |
| @@ -137,8 +138,12 @@ public class ExportVideo : MonoBehaviour { | @@ -137,8 +138,12 @@ public class ExportVideo : MonoBehaviour { | ||
| 137 | startExport(); | 138 | startExport(); |
| 138 | } | 139 | } |
| 139 | 140 | ||
| 140 | - | ||
| 141 | - | 141 | + } |
| 142 | + else | ||
| 143 | + { | ||
| 144 | + screenManager.showPermissionDialog("Para salvar e compartilhar as animações, permita que o Vlibras acesse mídia e arquivos de seu aparelho.", "Exportar Vìdeo"); | ||
| 145 | + | ||
| 146 | + } | ||
| 142 | 147 | ||
| 143 | } | 148 | } |
| 144 | 149 |
Assets/Scripts/Export Video/ShareIOS.cs
| @@ -2,14 +2,40 @@ | @@ -2,14 +2,40 @@ | ||
| 2 | using System.Collections; | 2 | using System.Collections; |
| 3 | using System.Runtime.InteropServices; | 3 | using System.Runtime.InteropServices; |
| 4 | using System.IO; | 4 | using System.IO; |
| 5 | +using System; | ||
| 6 | + | ||
| 5 | 7 | ||
| 6 | /* | 8 | /* |
| 7 | * https://github.com/ChrisMaire/unity-native-sharing | 9 | * https://github.com/ChrisMaire/unity-native-sharing |
| 8 | */ | 10 | */ |
| 9 | 11 | ||
| 10 | public class ShareIOS : MonoBehaviour { | 12 | public class ShareIOS : MonoBehaviour { |
| 13 | + private static ShareIOS instance; | ||
| 14 | + | ||
| 15 | + private static Action<bool> PermittedAction; | ||
| 16 | + private static bool initialized = false; | ||
| 17 | + | ||
| 18 | + public void Awake() | ||
| 19 | + { | ||
| 20 | + instance = this; | ||
| 21 | + DontDestroyOnLoad(this.gameObject); | ||
| 22 | + | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + private static void initialize() | ||
| 27 | + { | ||
| 28 | + | ||
| 29 | + if(instance == null) | ||
| 30 | + { | ||
| 31 | + GameObject go = new GameObject(); | ||
| 32 | + instance = go.AddComponent<ShareIOS>(); | ||
| 33 | + go.name = "ShareIOS"; | ||
| 34 | + } | ||
| 35 | + initialized = true; | ||
| 36 | + } | ||
| 11 | 37 | ||
| 12 | - public void Share(string shareText, string imagePath, string url, string subject) | 38 | + public void Share(string shareText, string imagePath, string url, string subject) |
| 13 | { | 39 | { |
| 14 | #if UNITY_IOS | 40 | #if UNITY_IOS |
| 15 | CallSocialShareAdvanced(shareText, subject, url, imagePath); | 41 | CallSocialShareAdvanced(shareText, subject, url, imagePath); |
| @@ -67,5 +93,37 @@ public class ShareIOS : MonoBehaviour { | @@ -67,5 +93,37 @@ public class ShareIOS : MonoBehaviour { | ||
| 67 | 93 | ||
| 68 | } | 94 | } |
| 69 | 95 | ||
| 70 | - #endif | 96 | + [DllImport("__Internal")] private static extern void askForPermission(ref ConfigStruct conf); |
| 97 | + | ||
| 98 | + public static void AskForPermission(Action<bool> CallBack) | ||
| 99 | + { | ||
| 100 | + if (!initialized) | ||
| 101 | + initialize(); | ||
| 102 | + PermittedAction = CallBack; | ||
| 103 | + ConfigStruct conf = new ConfigStruct(); | ||
| 104 | + conf.title = "ShareIOS"; | ||
| 105 | + conf.message = "ResponseFromIOS"; | ||
| 106 | + askForPermission(ref conf); | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + private void ResponseFromIOS(string response) | ||
| 110 | + { | ||
| 111 | + if (PermittedAction != null) | ||
| 112 | + { | ||
| 113 | + if (response == "PERMITIDO") | ||
| 114 | + { | ||
| 115 | + PermittedAction(true); | ||
| 116 | + } | ||
| 117 | + else | ||
| 118 | + { | ||
| 119 | + PermittedAction(false); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + } | ||
| 123 | + PermittedAction = null; | ||
| 124 | + | ||
| 125 | + | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | +#endif | ||
| 71 | } | 129 | } |