- Home /
PostProcessing iOS Activate Background Mode for Push Notifications
I have a lot of postprocessing in my apps, but there is something I haven't been able to automate.
On xCode, under Capabilities>Background Modes There are a couple of checkboxes. Including one to enable push notifications.
Has anyone been able to make a postprocessor script that enables those checkboxes?
Answer by La pieuvre · Dec 17, 2015 at 11:04 AM
hello,
From that post : http://forum.unity3d.com/threads/how-can-you-add-items-to-the-xcode-project-targets-info-plist-using-the-xcodeapi.330574/ by modifying a bit the script i got that :
[PostProcessBuild]
public static void ChangeXcodePlist(BuildTarget buildTarget, string pathToBuiltProject) {
if (buildTarget == BuildTarget.iOS) {
// Get plist
string plistPath = pathToBuiltProject + "/Info.plist";
PlistDocument plist = new PlistDocument();
plist.ReadFromString(File.ReadAllText(plistPath));
// Get root
PlistElementDict rootDict = plist.root;
// Change value of CFBundleVersion in Xcode plist
var buildKey = "UIBackgroundModes";
rootDict.CreateArray (buildKey).AddString ("remote-notification");
// Write to file
File.WriteAllText(plistPath, plist.WriteToString());
}
}
i just did it, it seems to work, need further test though.
Edit : Note that the script should be in Assets/Editor folder. Edit 2 : i created i string it should be a array, i changed the code.
Your answer
Follow this Question
Related Questions
AWS in iOS not working 2 Answers
How to solve ITMS-90809: Deprecated API Usage? 0 Answers
XCode Debugger crash, but game runs on phone 0 Answers
Error building to iPhone simulator 1 Answer