I ended up using the PostprocessBuildPlayer script (see the Unity manual entry for “Build Player Pipeline”) to patch the project.pbxproj used by Xcode.
This script is run after the Xcode project is created, but before it is built or run.
In the script, I patch the project.pbxproj to include the references to StoreKit. To get the info, I modified an existing project in Xcode, noticed what was changed in the project, and incorporated those changes into a diff.
//
// Copyright (c) 2017 eppz! mobile, Gergely Borbás (SP)
//
// http://www.twitter.com/_eppz
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
// OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.IO;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;
public class BuildPostProcessor
{
[PostProcessBuildAttribute(1)]
public static void OnPostProcessBuild(BuildTarget target, string path)
{
if (target == BuildTarget.iOS)
{
// Read.
string projectPath = PBXProject.GetPBXProjectPath(path);
PBXProject project = new PBXProject();
project.ReadFromString(File.ReadAllText(projectPath));
string targetName = PBXProject.GetUnityTargetName(); // note, not "project." ...
string targetGUID = project.TargetGuidByName(targetName);
AddFrameworks(project, targetGUID);
// Write.
File.WriteAllText(projectPath, project.WriteToString());
}
}
static void AddFrameworks(PBXProject project, string targetGUID)
{
// Frameworks (eppz! Photos, Google Analytics).
project.AddFrameworkToProject(targetGUID, "MessageUI.framework", false);
project.AddFrameworkToProject(targetGUID, "AdSupport.framework", false);
project.AddFrameworkToProject(targetGUID, "CoreData.framework", false);
project.AddFrameworkToProject(targetGUID, "SystemConfiguration.framework", false);
project.AddFrameworkToProject(targetGUID, "libz.dylib", false);
project.AddFrameworkToProject(targetGUID, "libsqlite3.tbd", false);
// Add `-ObjC` to "Other Linker Flags".
project.AddBuildProperty(targetGUID, "OTHER_LDFLAGS", "-ObjC");
}
}
I used a post build processor as well, but only to add the framework in the OTHER_LDFLAGS, e.g
OTHER_LDFLAGS = (
-weak_framework
PassKit
);
did not use any script though, since the ref provided in the previous answer did not seem to work for me, and required some install packages I did not have on my box…
I used this solution: build the project, copy the project file, then add the framework in xcode and compare the project file to the old one we saved… (svn merge, whatever you like…) Now you can see the difference that you need to add. Of course you can go around the string editing part in many ways… I chose the most stupid one I “Replace()” the above/below line to my desired framework with that framework.
On each and every export to iOS/XCode, I always had to manually edit the xcode project. I had to keep a checklist of things to do, as they were so many. Especially since we use a lot of 3rd party frameworks of which most require a few steps in order to work. It was hell, for months. I needed to automate it. But to do that, was another hell. Being busy with other work but I think I finally did it…
My solution is not maybe so much different from above ones, but it depends mostly on “xcodeapi”, with classes like PBXProject. This couple of classes are actually made by UT (it looks like) and is available in one of those open code repositories. Always forget the name.
I accomplished all these things at build time:
Set iOS 64 bit related options before compile
Set a new temp output folder, with an incrementally increased integer at the end so I always get fresh new folders.
Add extra internal frameworks (Social.framework etc)
Extra linker flags
Add extra files to project from plugins folder, like plists…
Add more lines to the .pch file
Delete keys from Info.plist, in order to remove entries like CFBundleIconFiles etc
Add extra entries to stuff in Info.plist, like requirements (gamekit)
Add extra URL schemes. Well that’s the Info.plist again.
Add one folder containing lots of subfolders containing 3rd party frameworks. Not libraries… Framework. This took me the longest. I couldn’t get UT’s code to add the folders the right way. Maybe I used it wrong or something. But only when I made use of an external Python library to add folders, I could get it working. The script was pbxproj.
Last, I had to actually subclass UnityAppController in order to add a few things to didFinishLaunchingWithOptions, and a few other stuff. For this I also have to edit the main.mm file, in order to choose my custom app delegate class instead of Unity’s one. This step I actually have yet to do… but it’ll be the last for one and should be possible with some regex work.
Probably forgot something. ANyway the above just took a long time to do, nothing fancy, except pbxproj which is the best place to start out… took me a lot of trial and error to find that project. It works well even for Xcode 6, even though it only states that it works with Xcode 4.