Skip to content

Handle custom iOS AppDelegate #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions SingularSDK/Editor/SingularEditorParams.cs
Original file line number Diff line number Diff line change
@@ -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 );
}
}
}
3 changes: 3 additions & 0 deletions SingularSDK/Editor/SingularEditorParams.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions SingularSDK/Editor/SingularPostBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static void OnPostProcessBuild(BuildTarget target, string pathToBuiltProject)
{
Debug.Log("Start Xcode project related configuration of SDK......");
AddiOSDependencies(pathToBuiltProject);
HandleCustomAppDelegate(pathToBuiltProject);
}
}

Expand Down Expand Up @@ -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
Expand Down