- Home /
Unity Mobile Notifications does not add Push Notification Capability to XCode Project
My Unity 2019.3 project is using the Unity Mobile Notifications library, version 1.0.3
using Unity.Notifications.iOS;
According to the Player Settings iOS documentation, the "Automatically add capabilities" option (when checked) should add the "Push Notifications" capability to my XCode project. I do not see this behavior occurring.
I tried including the legacy system in my code to nudge the "Automatically add capabilities" feature. No effect.
Debug.Log(UnityEngine.iOS.NotificationServices.deviceToken);
I tried adding the capability with a post-build script. No effect.
public void OnPostprocessBuild(BuildReport report)
{
if (report.summary.platform != BuildTarget.iOS) return;
var file_name = "gamename.entitlements";
var buildPath = report.summary.outputPath;
var proj_path = PBXProject.GetPBXProjectPath(buildPath);
Debug.Log("proj_path: " + proj_path);
var proj = new PBXProject();
proj.ReadFromFile(proj_path);
var target_name = "Unity-iPhone";
var target_guid = proj.GetUnityMainTargetGuid();
string entitlementsFilePath = target_name + "/" + file_name;
var capManager = new ProjectCapabilityManager(proj_path, entitlementsFilePath, target_name, target_guid);
capManager.AddPushNotifications(development: false);
capManager.WriteToFile();
}
I have noticed that there are two entitlement files: "Entitlements.entitlements", and "gamename.entitlements".
"Entitlements.entitlements" has a single entry for SignInWithApple that IS added to the XCode project Capabilities. "gamename.entitlements" has a single entry for APS Environment that IS NOT added to the XCode project Capabilities.
I suspect these files have something to do with this madness. Please help.
Answer by greglieb · Mar 19, 2021 at 07:15 AM
Thanks. Those troubleshooting steps plus deleting and rebuilding my XCode project fixed it.
I figured it's been so long it wasn't an issue for you anymore. Just wanted to help with anybody else who found this post in their search for an answer.
Your answer
Follow this Question
Related Questions
Xcode DebugFocusItem 0 Answers
Unity edit UnityAppController.mm when build iOS 0 Answers
IOS append not working? 0 Answers
Xcode build fails, How to ? 1 Answer