「Unity/URLからアプリ起動/iOS」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→Content-Typeをapplication/jsonへ) |
|||
| (同じ利用者による、間の13版が非表示) | |||
| 行1: | 行1: | ||
| + | ==Unity処理== | ||
| + | [[Unity/URLからアプリ起動/基本]] [ショートカット] | ||
| + | |||
==iOSの場合== | ==iOSの場合== | ||
| 行4: | 行7: | ||
例: | 例: | ||
| − | ttps:// | + | ttps://example.com/.well-known/apple-app-site-association |
MIME が application/json にする。 | MIME が application/json にする。 | ||
| 行15: | 行18: | ||
{ | { | ||
"appIDs": ["TEAMID.bundleid"], | "appIDs": ["TEAMID.bundleid"], | ||
| − | "paths": [ "/invite*" ] | + | "paths": [ |
| + | "/invite*", | ||
| + | "/invite/*" | ||
| + | ] | ||
} | } | ||
] | ] | ||
| 行35: | 行41: | ||
Header set Content-Type "application/json" | Header set Content-Type "application/json" | ||
</Files> | </Files> | ||
| + | </pre> | ||
| + | |||
| + | 確認 | ||
| + | <pre> | ||
| + | $ curl -I ttps://example.com/.well-known/apple-app-site-association | ||
| + | |||
| + | HTTP/2 200 | ||
| + | server: nginx | ||
| + | date: Thu, 04 Dec 2025 18:18:45 GMT | ||
| + | content-type: application/json | ||
| + | </pre> | ||
| + | ===Unityアプリ側設定=== | ||
| + | xcodeの設定を自動で追加する。(例:example.com) | ||
| + | |||
| + | Assets/Editor/XcodeAssociatedDomainsPostProcess.cs | ||
| + | <pre> | ||
| + | using UnityEditor; | ||
| + | using UnityEditor.Callbacks; | ||
| + | using UnityEditor.iOS.Xcode; | ||
| + | using System.IO; | ||
| + | |||
| + | public class XcodeAssociatedDomainsPostProcess | ||
| + | { | ||
| + | [PostProcessBuild] | ||
| + | public static void OnPostProcessBuild(BuildTarget target, string path) | ||
| + | { | ||
| + | if (target != BuildTarget.iOS) return; | ||
| + | |||
| + | string projPath = PBXProject.GetPBXProjectPath(path); | ||
| + | PBXProject proj = new PBXProject(); | ||
| + | proj.ReadFromFile(projPath); | ||
| + | |||
| + | string targetGuid = proj.GetUnityMainTargetGuid(); | ||
| + | |||
| + | // 1. entitlements ファイルのパス | ||
| + | string entitlementsPath = Path.Combine(path, "Unity-iPhone.entitlements"); | ||
| + | |||
| + | // 2. entitlements がなければ作る | ||
| + | if (!File.Exists(entitlementsPath)) | ||
| + | { | ||
| + | var plist = new PlistDocument(); | ||
| + | plist.root.CreateArray("com.apple.developer.associated-domains"); | ||
| + | File.WriteAllText(entitlementsPath, plist.WriteToString()); | ||
| + | } | ||
| + | |||
| + | // 3. entitlements をプロジェクトに追加 | ||
| + | proj.AddFile(entitlementsPath, "Unity-iPhone.entitlements"); | ||
| + | proj.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", "Unity-iPhone.entitlements"); | ||
| + | |||
| + | // 4. entitlements に applinks を追加 | ||
| + | var ent = new PlistDocument(); | ||
| + | ent.ReadFromFile(entitlementsPath); | ||
| + | var array = ent.root["com.apple.developer.associated-domains"].AsArray(); | ||
| + | array.values.Clear(); | ||
| + | array.AddString("applinks:example.com"); | ||
| + | File.WriteAllText(entitlementsPath, ent.WriteToString()); | ||
| + | |||
| + | // 5. Capability を追加(ここで entitlementsPath が必要) | ||
| + | proj.AddCapability(targetGuid, PBXCapabilityType.AssociatedDomains, "Unity-iPhone.entitlements", false); | ||
| + | |||
| + | proj.WriteToFile(projPath); | ||
| + | } | ||
| + | } | ||
| + | </pre> | ||
| + | iOSビルドすれば良い。 | ||
| + | |||
| + | ====xcode確認==== | ||
| + | 例:example.com | ||
| + | |||
| + | ビルド後xcodeのSigning&CapabilitiesのAssociatedDomainsにapplinksに、example.comドメインが、追加されてれば良い。 | ||
| + | |||
| + | ===iPhone実機での動作=== | ||
| + | iPhoneとかの、safariで、以下を開くと、アプリが起動する。 | ||
| + | ttps://example.com/invite | ||
| + | |||
| + | 開かない場合は、まだファイルが、読み込めてない場合があるので、30分~2時間ぐらい待ってみる。 | ||
| + | |||
| + | ===apple-app-site-associationについて複数アプリの設定をする場合=== | ||
| + | apple-app-site-association | ||
| + | <pre> | ||
| + | { | ||
| + | "applinks": { | ||
| + | "details": [ | ||
| + | { | ||
| + | "appIDs": ["8VA6UXXXXX.com.example.app1"], | ||
| + | "paths": [ | ||
| + | "/invite*", | ||
| + | "/invite/*" | ||
| + | ] | ||
| + | }, | ||
| + | { | ||
| + | "appIDs": ["8VA6UXXXXX.com.example.app2"], | ||
| + | "paths": [ | ||
| + | "/invite*", | ||
| + | "/invite/*" | ||
| + | ] | ||
| + | } | ||
| + | ] | ||
| + | } | ||
| + | } | ||
</pre> | </pre> | ||
2025年12月6日 (土) 10:30時点における最新版
目次
Unity処理
Unity/URLからアプリ起動/基本 [ショートカット]
iOSの場合
独自ドメインで、公開場所に、apple-app-site-associationファイルを用意
例:
ttps://example.com/.well-known/apple-app-site-association
MIME が application/json にする。
apple-app-site-association ファイルの中身
{
"applinks": {
"details": [
{
"appIDs": ["TEAMID.bundleid"],
"paths": [
"/invite*",
"/invite/*"
]
}
]
}
}
appIDsの部分の例
TEAMID:8VA6Uxxxxx bundleid:com.example.app1 appIDs:8VA6Uxxxxx.com.example.app1
Content-Typeをapplication/jsonへ
.well-known/.htaccess を設置
<Files "apple-app-site-association">
ForceType application/json
Header set Content-Type "application/json"
</Files>
確認
$ curl -I ttps://example.com/.well-known/apple-app-site-association HTTP/2 200 server: nginx date: Thu, 04 Dec 2025 18:18:45 GMT content-type: application/json
Unityアプリ側設定
xcodeの設定を自動で追加する。(例:example.com)
Assets/Editor/XcodeAssociatedDomainsPostProcess.cs
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
using System.IO;
public class XcodeAssociatedDomainsPostProcess
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.iOS) return;
string projPath = PBXProject.GetPBXProjectPath(path);
PBXProject proj = new PBXProject();
proj.ReadFromFile(projPath);
string targetGuid = proj.GetUnityMainTargetGuid();
// 1. entitlements ファイルのパス
string entitlementsPath = Path.Combine(path, "Unity-iPhone.entitlements");
// 2. entitlements がなければ作る
if (!File.Exists(entitlementsPath))
{
var plist = new PlistDocument();
plist.root.CreateArray("com.apple.developer.associated-domains");
File.WriteAllText(entitlementsPath, plist.WriteToString());
}
// 3. entitlements をプロジェクトに追加
proj.AddFile(entitlementsPath, "Unity-iPhone.entitlements");
proj.AddBuildProperty(targetGuid, "CODE_SIGN_ENTITLEMENTS", "Unity-iPhone.entitlements");
// 4. entitlements に applinks を追加
var ent = new PlistDocument();
ent.ReadFromFile(entitlementsPath);
var array = ent.root["com.apple.developer.associated-domains"].AsArray();
array.values.Clear();
array.AddString("applinks:example.com");
File.WriteAllText(entitlementsPath, ent.WriteToString());
// 5. Capability を追加(ここで entitlementsPath が必要)
proj.AddCapability(targetGuid, PBXCapabilityType.AssociatedDomains, "Unity-iPhone.entitlements", false);
proj.WriteToFile(projPath);
}
}
iOSビルドすれば良い。
xcode確認
例:example.com
ビルド後xcodeのSigning&CapabilitiesのAssociatedDomainsにapplinksに、example.comドメインが、追加されてれば良い。
iPhone実機での動作
iPhoneとかの、safariで、以下を開くと、アプリが起動する。 ttps://example.com/invite
開かない場合は、まだファイルが、読み込めてない場合があるので、30分~2時間ぐらい待ってみる。
apple-app-site-associationについて複数アプリの設定をする場合
apple-app-site-association
{
"applinks": {
"details": [
{
"appIDs": ["8VA6UXXXXX.com.example.app1"],
"paths": [
"/invite*",
"/invite/*"
]
},
{
"appIDs": ["8VA6UXXXXX.com.example.app2"],
"paths": [
"/invite*",
"/invite/*"
]
}
]
}
}
