using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.iOS.Xcode;
using UnityEditor.Callbacks;
using System.Collections;
public class XCodeSettingsPostProcesser
{
[PostProcessBuild]
public static void OnPostprocessBuild(BuildTarget buildTarget, string pathToBuiltProject)
{
// Stop processing if targe is NOT iOS
if (buildTarget != BuildTarget.iOS)
{
return;
}
/// Initialize PbxProject
var projectPath = PBXProject.GetPBXProjectPath(pathToBuiltProject);
PBXProject pbxProject = new PBXProject();
pbxProject.ReadFromFile(projectPath);
// Unity 2019 대응
#if UNITY_2019_3_OR_NEWER
//string targetGuid = pbxProject.GetUnityFrameworkTargetGuid();
string strMainTargetGuid = pbxProject.GetUnityMainTargetGuid();
string strFrameworkTargetGuid = pbxProject.GetUnityFrameworkTargetGuid();
#else
string targetGuid = pbxProject.TargetGuidByName("Unity-iPhone");
#endif
// Add push notifications as a capability on the target
pbxProject.AddCapability(targetGuid, UnityEditor.iOS.Xcode.Custom.PBXCapabilityType.PushNotifications);
// Apply settings
File.WriteAllText(projectPath, pbxProject.WriteToString());
}
}
3-1) 주의사항
기존 PBXProject는 UnityEditor.iOS.Xcode.PBXProject인데, 추가 된 플러그인을 사용하기 위해 UnityEditor.iOS.Xcode.Custom.PBXProject로 변경필요.
I manage to get it working by a C# script, but since this build setting need an.entitlementfile in your xcode project, first you will need to create a text file called[projectName].entitlementanywhere in your project with this content:
After that you just define the entitlementsFile variable for the script in the inspector window and you should now have the push notification activated by default when you build for iOS.
Unity에서 Firebase Cloud Messaging(FCM) 서비스 적용 후 빌드 시, 애플로부터 Missing Push Notification Entitlement 메시지를 받을 때가 있는데 어느 순간 부터 XCode에서 Capabilities-Push Notifications를 수동으로 ON 시켜줘야 된단다.
[참조]
7단계: 사용자 알림 프레임워크 추가
Xcode 프로젝트를 클릭한 후Editor area(편집 영역)에서General(일반)탭을 클릭합니다.
Linked Frameworks and Libraries(연결된 프레임워크 및 라이브러리)까지 아래로 스크롤한 다음+버튼을 클릭하여 프레임워크를 추가합니다.
나타나는 창에서UserNotifications.framework까지 스크롤하여 해당 항목을 클릭한 다음Add(추가)를 클릭합니다.
8단계: 푸시 알림 사용 설정
Xcode 프로젝트를 클릭한 후Editor area(편집 영역)에서Capabilities(기능)탭을 클릭합니다.
Push Notifications(푸시 알림)를 On(켜기)으로 전환합니다.
Background Modes(백그라운드 모드)까지 아래로 스크롤하고On(켜기)으로 전환합니다.