类似以下的东西应该可以工作(取自我创建的使用 xcodebuild 命令行工具构建应用程序的项目):
- (BOOL)createSignedIPA:(NSError **)error
{
[self.delegate builder:self didUpdateStatus:@"creating IPA, please be patient ..."];
NSTask *task = [[NSTask alloc] init];
NSString *path = @"/usr/bin/xcrun";
[task setLaunchPath: path];
NSString *input = [MOB_PROJECT_DIR stringByExpandingTildeInPath];
input = [NSString stringWithFormat:@"%@/build/%@-iphoneos/yourapp.app", input, isDemoApp ? @"Debug" : @"Release"];
NSString *output = [@"~/Desktop" stringByExpandingTildeInPath];
output = [NSString stringWithFormat:@"%@/%@%ld.ipa", output, isDemoApp ? @"demo" : @"app", appIdentifier];
NSString *bundleIdentifier = [self bundleIdentifier];
NSString *profile = [self pathForProfileWithBundleIdentifier:bundleIdentifier error:error];
if (!profile)
if (*error)
return NO;
else
{
NSString *message = [NSString stringWithFormat:@"no profile found for bundle %@", bundleIdentifier];
NSDictionary *userInfo = [NSDictionary dictionaryWithObject:message forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:MOB_APP_DOMAIN code:MOB_ERR_PROFILE_NOT_FOUND userInfo:userInfo];
return NO;
}
NSLog(@"%@", profile);
NSArray *arguments = [NSArray arrayWithObjects:
@"-sdk", @"iphoneos5.0",
@"PackageApplication", input,
@"-o", output,
@"--sign", isDemoApp ? @"Wolfgang Schreurs (YK9DVMECC4)" : @"My Company",
@"--embed", profile,
@"-verbose",
nil];
[task setArguments:arguments];
NSString *projectDirectory = [MOB_PROJECT_DIR stringByExpandingTildeInPath];
[task setCurrentDirectoryPath:projectDirectory];
NSPipe *pipe = [NSPipe pipe];
[task setStandardOutput: pipe];
[task setStandardInput:[NSPipe pipe]];
NSFileHandle *file = [pipe fileHandleForReading];
[task launch];
NSData *data = [file readDataToEndOfFile];
NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
[self.delegate builder:self didUpdateStatus:string];
return YES;
}
~/Library/MobileProvisioning
在上面的这个片段中,我从构建目录中获取 *.app 并使用来自(或类似的东西)的配置文件创建一个签名的 IPA 。