gpt4 book ai didi

ios - 如何使用 Xcode 制作一个 imessage 扩展包以便可以导入

转载 作者:行者123 更新时间:2023-11-29 00:10:48 30 4
gpt4 key购买 nike

我们使用Unity生成一个项目到Xcode,并希望利用iMessage扩展,但唯一的方法是在Unity生成Xcode项目后进行扩展,所以每次我们构建项目时我们应该重新设置 iMessage 扩展。

尽管我们已将 iMessage 扩展制作为一个文件夹并保存在磁盘上,因此每次生成 Xcode 项目时我们都必须

  1. 使用 Xcode 添加 iMessage 扩展功能。
  2. 将某些内容拖到 Xcode 中,以使用预制代码覆盖生成的代码。

这个过程很烦人,所以我们正在寻找其他一些容易做到这一点的方法。

有什么办法可以做到这一点吗?谢谢。

最佳答案

是的,您可以为此使用 Unity xcode api参见 https://bitbucket.org/Unity-Technologies/xcodeapi

基本上,您创建一个构建后处理器,它创建一个新目标并将标签资源添加到新生成的构建中。

using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using MightyEditor.iOS.Xcode;

public class BuildPostProcessor
{
[PostProcessBuild(2000)]
public static void OnPostProcessBuild(BuildTarget buildTarget, string buildPath)
{
Debug.Log("------ buildTarget:" + buildTarget + " path:" + buildPath);

if (buildTarget == BuildTarget.iOS)
{
string xcodeprojPath = buildPath + "/Unity-iPhone.xcodeproj";
string pbxprojPath = xcodeprojPath + "/project.pbxproj";

PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromFile(pbxprojPath);

AddStickers(pbxProject, buildPath, xcodeprojPath, pbxprojPath);

pbxProject.WriteToFile(pbxprojPath);
}
}

private static void AddStickers(PBXProject pbxProject, string buildPath,string xcodeprojPath,string pbxprojPath)
{
string appGuid = pbxProject.TargetGuidByName(PBXProject.GetUnityTargetName());
DirectoryCopy("_Stickers", buildPath + "/Stickers", true);

string stickersGuid = pbxProject.AddAppExtension(appGuid, "stickers app", "com.apple.product-type.app-extension.messages-sticker-pack", "Stickers/Info.plist");

pbxProject.AddFile("Stickers/Stickers.xcassets", "Stickers/Stickers.xcassets");
pbxProject.AddFileToResourcesForTarget(stickersGuid, "Stickers/Stickers.xcassets");

pbxProject.AddBuildProperty(stickersGuid, "PRODUCT_BUNDLE_IDENTIFIER", "com.blABLA");
pbxProject.AddBuildProperty(stickersGuid, "TARGETED_DEVICE_FAMILY", "1,2");
pbxProject.AddBuildProperty(stickersGuid, "ASSETCATALOG_COMPILER_APPICON_NAME", "iMessage App Icon");
pbxProject.AddBuildProperty(stickersGuid, "ARCHS", "armv7 arm64");
pbxProject.SetBuildProperty(stickersGuid, "IPHONEOS_DEPLOYMENT_TARGET", "10.0");
pbxProject.SetBuildProperty(stickersGuid, "DEVELOPMENT_TEAM", "TEAMid");

//Info.plist update
string plistPath = buildPath + "/Stickers/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));

// Get root
PlistElementDict rootDict = plist.root;

rootDict.values["CFBundleVersion"] = new PlistElementString(PlayerSettings.iOS.buildNumber);
rootDict.values["CFBundleShortVersionString"] = new PlistElementString(PlayerSettings.bundleVersion);

// Write to info.plist file
File.WriteAllText(plistPath, plist.WriteToString());

// This is quite yuck, but there isn't a way with Unity's PBX library to add a scheme and we need to add one for the Stickers target or else xcodebuild fails when we try to build it
File.WriteAllText(xcodeprojPath + "/xcshareddata/xcschemes/Stickers.xcscheme", "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Scheme LastUpgradeVersion = \"0800\" wasCreatedForAppExtension = \"YES\" version = \"2.0\"><BuildAction parallelizeBuildables = \"YES\" buildImplicitDependencies = \"YES\"><BuildActionEntries><BuildActionEntry buildForTesting = \"YES\" buildForRunning = \"YES\" buildForProfiling = \"YES\" buildForArchiving = \"YES\" buildForAnalyzing = \"YES\"><BuildableReference BuildableIdentifier = \"primary\" BlueprintIdentifier = \"" + stickersGuid + "\" BuildableName = \"Stickers.appex\" BlueprintName = \"Stickers\" ReferencedContainer = \"container:Unity-iPhone.xcodeproj\"></BuildableReference></BuildActionEntry></BuildActionEntries></BuildAction><TestAction buildConfiguration = \"Debug\" selectedDebuggerIdentifier = \"Xcode.DebuggerFoundation.Debugger.LLDB\" selectedLauncherIdentifier = \"Xcode.DebuggerFoundation.Launcher.LLDB\" shouldUseLaunchSchemeArgsEnv = \"YES\"><Testables></Testables><MacroExpansion><BuildableReference BuildableIdentifier = \"primary\" BlueprintIdentifier = \"" + appGuid + "\" BuildableName = \"Unity-Target-New.app\" BlueprintName = \"Unity-iPhone\" ReferencedContainer = \"container:Unity-iPhone.xcodeproj\"></BuildableReference></MacroExpansion><AdditionalOptions></AdditionalOptions></TestAction><LaunchAction buildConfiguration = \"Debug\" selectedDebuggerIdentifier = \"\" selectedLauncherIdentifier = \"Xcode.IDEFoundation.Launcher.PosixSpawn\" launchStyle = \"0\" useCustomWorkingDirectory = \"NO\" ignoresPersistentStateOnLaunch = \"NO\" debugDocumentVersioning = \"YES\" debugServiceExtension = \"internal\" allowLocationSimulation = \"YES\" launchAutomaticallySubstyle = \"2\"><AdditionalOptions></AdditionalOptions></LaunchAction><ProfileAction buildConfiguration = \"Release\" shouldUseLaunchSchemeArgsEnv = \"YES\" savedToolIdentifier = \"\" useCustomWorkingDirectory = \"NO\" debugDocumentVersioning = \"YES\" launchAutomaticallySubstyle = \"2\"><MacroExpansion><BuildableReference BuildableIdentifier = \"primary\" BlueprintIdentifier = \"" + stickersGuid + "\" BuildableName = \"Stickers.appex\" BlueprintName = \"Stickers\" ReferencedContainer = \"container:Unity-iPhone.xcodeproj\"></BuildableReference></MacroExpansion></ProfileAction><AnalyzeAction buildConfiguration = \"Debug\"></AnalyzeAction><ArchiveAction buildConfiguration = \"Release\" revealArchiveInOrganizer = \"YES\"></ArchiveAction></Scheme>");
}

private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool overrideDest = false)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
}

DirectoryInfo[] dirs = dir.GetDirectories();
// If the destination directory doesn't exist, create it.
if (!Directory.Exists (destDirName)) {
Directory.CreateDirectory (destDirName);
}
else if(overrideDest)
{
Directory.Delete (destDirName, true);
Directory.CreateDirectory (destDirName);
}

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string temppath = Path.Combine(destDirName, file.Name);
file.CopyTo(temppath, overrideDest);
}

// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string temppath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, temppath, copySubDirs, overrideDest);
}
}
}
}

关于ios - 如何使用 Xcode 制作一个 imessage 扩展包以便可以导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46525060/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com