diff --git a/SingularSDK/Editor/SingularEditorParams.cs b/SingularSDK/Editor/SingularEditorParams.cs new file mode 100644 index 0000000..8e9906d --- /dev/null +++ b/SingularSDK/Editor/SingularEditorParams.cs @@ -0,0 +1,36 @@ +using UnityEditor; + +namespace Singular.Editor +{ + public static class SingularEditorParams + { + private const string IOS_USE_CUSTOM_APP_DELEGATE_EDITOR_KEY = "SingularIsIOSUseCustomAppDelegate"; + internal static bool IsIOSUseCustomAppDelegate => EditorPrefs.GetInt( IOS_USE_CUSTOM_APP_DELEGATE_EDITOR_KEY, 0 ) == 1; + + // IOS APP USES CUSTOM APP DELEGATE + + [MenuItem( "Window/Singular/My iOS App use a custom AppDelegate", true )] + private static bool _MenuItem_iOSUseCustomAppDelegate() + { + return !IsIOSUseCustomAppDelegate; + } + [MenuItem( "Window/Singular/My iOS App use a custom AppDelegate" )] + private static void MenuItem_iOSUseCustomAppDelegate() + { + EditorPrefs.SetInt( IOS_USE_CUSTOM_APP_DELEGATE_EDITOR_KEY, 1 ); + } + + // IOS APP DON'T USES CUSTOM APP DELEGATE + + [MenuItem( "Window/Singular/My iOS App don't use a custom AppDelegate", true )] + private static bool _MenuItem_iOSDontUseCustomAppDelegate() + { + return IsIOSUseCustomAppDelegate; + } + [MenuItem( "Window/Singular/My iOS App don't use a custom AppDelegate" )] + private static void MenuItem_iOSDontUseCustomAppDelegate() + { + EditorPrefs.SetInt( IOS_USE_CUSTOM_APP_DELEGATE_EDITOR_KEY, 0 ); + } + } +} \ No newline at end of file diff --git a/SingularSDK/Editor/SingularEditorParams.cs.meta b/SingularSDK/Editor/SingularEditorParams.cs.meta new file mode 100644 index 0000000..4a69053 --- /dev/null +++ b/SingularSDK/Editor/SingularEditorParams.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 58e0c8cb5925438790ea3a52154a5c20 +timeCreated: 1720604858 \ No newline at end of file diff --git a/SingularSDK/Editor/SingularPostBuild.cs b/SingularSDK/Editor/SingularPostBuild.cs index 093e4dc..eddc077 100644 --- a/SingularSDK/Editor/SingularPostBuild.cs +++ b/SingularSDK/Editor/SingularPostBuild.cs @@ -25,6 +25,7 @@ static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject) { Debug.Log("Start Xcode project related configuration of SDK......"); AddiOSDependencies(pathToBuiltProject); + HandleCustomAppDelegate(pathToBuiltProject); } } @@ -55,6 +56,22 @@ static void AddiOSDependencies(string pathToBuiltProject) // Save the changes to Xcode project file. pbxProject.WriteToFile(projectPath); } + + + static void HandleCustomAppDelegate(string pathToBuiltProject) + { + if( !SingularEditorParams.IsIOSUseCustomAppDelegate ) + return; + + // get the path to SingularAppDelegate.m in built project + var SingularAppDelegateFile = $"{pathToBuiltProject}/Libraries/singular-unity-package/SingularSDK/Plugins/iOS/SingularAppDelegate.m"; + // get the content + var SingularAppDelegateFileContent = File.ReadAllText(SingularAppDelegateFile); + // comment out the App delagate inplementation directive + var SingularAppDelegateFileReplacement = SingularAppDelegateFileContent.Replace("IMPL_APP_CONTROLLER_SUBCLASS(SingularAppDelegate)", "//IMPL_APP_CONTROLLER_SUBCLASS(SingularAppDelegate)"); + // save the modified file + File.WriteAllText( SingularAppDelegateFile, SingularAppDelegateFileReplacement); + } } #endif