#if APPLE
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class EntitlementsPostProcess : ScriptableObject
{
public DefaultAsset m_entitlementsFile;
[PostProcessBuild]
public static void OnPostProcess(BuildTarget buildTarget, string buildPath)
{
if (buildTarget != BuildTarget.iOS)
return;
var dummy = CreateInstance<EntitlementsPostProcess>();
var file = dummy.m_entitlementsFile;
DestroyImmediate(dummy);
if (file == null)
return;
var proj_path = PBXProject.GetPBXProjectPath(buildPath);
var proj = new PBXProject();
var unityFrameworkGUID = proj.GetUnityFrameworkTargetGuid();
proj.ReadFromFile(proj_path);
var target_name = proj.GetUnityMainTargetGuid();
// NEW
//Set the entitlements file name to what you want but make sure it has this extension
string entitlementsFileName = "my_app.entitlements";
var entitlements = new ProjectCapabilityManager(proj_path, entitlementsFileName, "Unity-iPhone", target_name);
entitlements.AddPushNotifications(true);
//Apply
entitlements.WriteToFile();
}
}
#endif
Try this, I removed a few things that I donāt think you need but hopefully should work.
Thank you for the solution, I suppose it should work because I see the entitlement finally set into production automatically and so does the background, push notification enabled in xcode automatically, but still when I try to send cloud messaging from firebase. My app just donāt receive it. Iām sure my firebase script and setting are correct since I can receive it on android.
What might be the problem. Is it because I run the app through test flight mode.
So I have followed the steps to upload my APN to firebase but still canāt get things going. Iāve checked my APN, package ID, App store ID, and team ID. All four sees correct.
The only thing I havenāt done is to configure the push notification under app id configuration because I realize to use keychain generating certificate is an old method (it eventually cannot export to p8 file).
Thanks! It finally gets to work after 24 hours of uploading my APN (cloud messaging wonāt start right away after uploaded). Thank you again, Iāve been working on this for two weeks.
We have a big problem with notifications and UCB.
For the third day I have been trying any options, but the cloud build refuses to assemble.
Unity version: 2022.2.14f
xcode version: 14.1
Mobile Provision was recreated after the push certificate was added.
True, in the mobile itself there is nothing about the notification service. Is this correct?
error from cloud
[error] 7.3.5.2.7.4 - INFO: āø /BUILD_PATH/Unity-iPhone.xcodeproj: error: Provisioning profile has app ID ācom.redrift.StorySparkā, which does not match the bundle ID ācom.redrift.StorySpark.notificationserviceā. (in target ānotificationserviceā from project āUnity-iPhoneā)
Here is the postbuild processing code we are using.
[PostProcessBuild(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
try
{
if (target != BuildTarget.iOS)
return;
Debug.Log($"{nameof(SignInWithApplePostprocessor)} Start Post Process Build");
var projectPath = PBXProject.GetPBXProjectPath(path);
var project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));
var projectCapabilityManager = new ProjectCapabilityManager(projectPath,
"Entitlements.entitlements",
null,
project.GetUnityMainTargetGuid());
projectCapabilityManager.AddSignInWithAppleWithCompatibility(project.GetUnityFrameworkTargetGuid());
projectCapabilityManager.AddPushNotifications(true);
projectCapabilityManager.WriteToFile();
Debug.Log(
$"{nameof(SignInWithApplePostprocessor)} End success Post Process Build. Entitlements: {string.Join(";", projectCapabilityManager.Entitlements.root.values.Select(x => x.Key))}");
}
catch (Exception e)
{
Debug.LogError(
$"{nameof(SignInWithApplePostprocessor)} End failed Post Process Build. Message: {e.Message}");
Debug.LogException(e);
throw;
}
}
private static readonly string SwiftStandardLibraries = "ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES";
private static readonly string BitCode = "ENABLE_BITCODE";
private static readonly string AlwaysSearchUserPaths = "ALWAYS_SEARCH_USER_PATHS";
private static readonly string UseHeadermap = "USE_HEADERMAP";
private static readonly string Notificationservice = "notificationservice";
private static readonly string No = nameof(No).ToUpper();
private static readonly string Yes = nameof(Yes).ToUpper();
[PostProcessBuild(999)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target != BuildTarget.iOS)
return;
try
{
Debug.Log($"{nameof(ModifyFrameworksPostProcess)} Start Post Process Build");
var projPath = PBXProject.GetPBXProjectPath(path);
Debug.Log($"{nameof(projPath)}: {projPath}");
var project = new PBXProject();
project.ReadFromFile(projPath);
Debug.Log($"{nameof(ModifyFrameworksPostProcess)} Project successfully initialized");
project.DisableSwiftStandardLibraries();
project.EnableSwiftStandardLibraries();
project.DisableBitcode();
project.DisableHeaderMap();
project.WriteToFile(projPath);
Debug.Log($"{nameof(ModifyFrameworksPostProcess)} End success Post Process Build");
}
catch (Exception e)
{
Debug.LogError(
$"{nameof(ModifyFrameworksPostProcess)} End failed Post Process Build. Message: {e.Message}");
Debug.LogException(e);
throw;
}
}
private static PBXProject DisableHeaderMap(this PBXProject project)
{
var notificationserviceGuid = project.TargetGuidByName(Notificationservice);
project.SafeSetBuildProperty(notificationserviceGuid, AlwaysSearchUserPaths, No);
project.SafeSetBuildProperty(notificationserviceGuid, UseHeadermap, No);
Debug.Log($"{nameof(ModifyFrameworksPostProcess)} {nameof(DisableHeaderMap)} end");
return project;
}
I omitted some methods, they do not apply to the work of other SDKs
I would be grateful if you give me more options. Or at least point to the cause of the problem
No. We tried different options.
Also tried to switch to the OneSignal.
Together with OneSiganl support, we came to the conclusion that Unity Cloud does not support building projects with push notifications.
Because for correct operation, it is required to use extensions that the cloud assembly cannot correctly sign
Forget it, this prevents installing it to a device.
So we opted to remove push notifications from ios builds:
internal class RemovePushNotifications : IPreprocessBuildWithReport
{
public int callbackOrder => -10000;
public void OnPreprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.iOS) return;
var request = UnityEditor.PackageManager.Client.Remove("com.unity.services.push-notifications");
while (!request.IsCompleted)
{
AssetDatabase.Refresh();
}
}
}