I have projects called A.xcodeproj, B.xcodeproj, C.xcodeproj
now what is question, in AppDelegate of Project A , open project B and C on condition.
int run;
run = 0;
if(run == 0)
{
Open project B.xcodeproj
}
else
{
Open project C.xcodeproj
}
Help
Thanks in Advance.
on the command line use open to OPEN and SHOW xcode.. so in your case, when run == 0
when you want to BUILD the xcode project, invoke xcodebuild instead of open!..so in your case, when run == 1
Related
I have a Cordova based iOS project in which I need to add a custom script to the build phases. I have one set up and it works fine, however I need to be able to add the build phase automatically somehow, as I need the project to be able to install and build automatically on a CI server, without having to manually add the phase in Xcode.
To clarify, when cordova platform add ios is run the project is created without build phases, I need to add a build phase in programmatically, before (or during) cordova build ios.
I can add custom build settings in the .xcconfig file, is there somewhere I can define build phases? I see that the build phase is present in my .pbxproj file, however this is automatically generated and contains some random IDs so I am not sure its something I can just parse and insert arbitrary stuff into?
The solution I have found is to use an Xcode project parser, there are a few around. I have used cordova-node-xcode. I couldn't find any API documentation but the unit tests were helpful in figuring out what I needed. I needed to use the proj.addBuildPhase method, an example of using this to add a run script can be seen here: https://github.com/apache/cordova-node-xcode/blob/master/test/addBuildPhase.js#L113
Based on an accepted answer i created the code maybe somebody can use it :)
Install xcode npm with:
npm i xcode
Create extend_build_phase.js in root:
var xcode = require('xcode');
var fs = require('fs');
var path = require('path');
const xcodeProjPath = fromDir('platforms/ios', '.xcodeproj', false);
const projectPath = xcodeProjPath + '/project.pbxproj';
const myProj = xcode.project(projectPath);
// Here you can add your own shellScript
var options = { shellPath: '/bin/sh', shellScript: 'echo "hello world!"' };
myProj.parse(function(err) {
myProj.addBuildPhase([], 'PBXShellScriptBuildPhase', 'Run a script',myProj.getFirstTarget().uuid, options);
fs.writeFileSync(projectPath, myProj.writeSync());
})
function fromDir(startPath, filter, rec, multiple) {
if (!fs.existsSync(startPath)) {
console.log("no dir ", startPath);
return;
}
const files = fs.readdirSync(startPath);
var resultFiles = [];
for (var i = 0; i < files.length; i++) {
var filename = path.join(startPath, files[i]);
var stat = fs.lstatSync(filename);
if (stat.isDirectory() && rec) {
fromDir(filename, filter); //recurse
}
if (filename.indexOf(filter) >= 0) {
if (multiple) {
resultFiles.push(filename);
} else {
return filename;
}
}
}
if (multiple) {
return resultFiles;
}
}
Extend config.xml with the following code:
<platform name="ios">
...
<hook src="extend_build_phase.js" type="after_platform_add" />
...
</platform>
I'm created an Ionic project so to make it work I use the following commands:
ionic cordova platform rm ios
ionic cordova platform add ios
ionic cordova build ios
I am receiving an error message when I try to use Xcode 8's Convert Wizard.
After trying rebooting, downloading fresh code, and deleting my DerivedData files I cannot escape this error:
Convert to Current Swift Syntax Failed: Could not find test host
I have tried both options which are: Swift 2.3 and Swift 3. After I select a version I instantly get that error.
Here is a screenshot of the error:
This worked for me:
Select the Xcode project in the lefthand browser.
Click on your test target in the Project's General tab.
Disclose "Testing". In my project the "Host Application" pulldown button was blank. Select your appropriate host application.
Try building your test target now. If that succeeds then converting syntax should as well.
I had this problem after installing the Xcode 8 beta so I assume this is related.
Picture Credit to #karthikkck
It cost me a bit of time to find the "Host Application" pulldown mentioned in the otherwise very helpful answer by iluvcapra.
So this is what he meant:
This is where you find the pulldown menu. Select your main target.
I find easy fix for this, just edit your Scheme and disable tests.
And run conversion again.
+1 iluvcapra
Alternatively, use text editor to remove the following two items from your MyAppSwift.xcodeproj/project.pbxproj file, search for TEST_HOST
Now, re-open your project and run the convert wizard again.
4EFFFAE51B53D5D8003CD25A /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
INFOPLIST_FILE = "AF SwiftTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) #executable_path/Frameworks #loader_path/Frameworks";
PRODUCT_NAME = "FA SwiftTests";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AF Swift.app/AF Swift";
};
name = Debug;
};
4EFFFAE61B53D5D8003CD25A /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(TEST_HOST)";
FRAMEWORK_SEARCH_PATHS = (
"$(SDKROOT)/Developer/Library/Frameworks",
"$(inherited)",
);
INFOPLIST_FILE = "AF SwiftTests/Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) #executable_path/Frameworks #loader_path/Frameworks";
PRODUCT_NAME = "FA SwiftTests";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/AF Swift.app/AF Swift";
};
name = Release;
};
Please try these Steps:
Select your project on the left side of Xcode.
Go to Targets and select your Project Tests.
Select the General Tab and select Host Application drop down and choose your Host Application.
Convert or Run your project.
Trying these steps worked for me.
In my case I deleted my tests target, then re-added it using the + below targets and selecting "iOs Unit Testing Bundle"
For some reason this got a compile error, so I changed the "Per-configuration Intermediate Build Files Path: for my test target to $(PROJECT_TEMP_DIR)/$(CONFIGURATION) for both debug and release. This allowed the compile to work.
Fix this in 3 steps:
First delete your test target
The select Edit -> Convert -> To current Swift syntax... and perform the conversion
Then add a new test target
I am porting old vm unittest files using the new test package. Some relies on input files in sub directories of my test folder. Before I was using Platform.script to find the location of such files. This works fine when using
$ dart test/my_test.dart
However using
$ pub run test
this is now pointing to a temp folder (tmp/dart_test_xxxx/runInIsolate.dart). I am unable to locate my test input files anymore. I cannot rely on the current path as I might run the test from a different working directory.
Is there a way to find the location of my_test.dart (or event the project root path), from which I could derive the locations of my files?
This is a current limitation of pub run.
What I currently do when I run into such requirements is to set an environment variable and read them from within the tests.
I have them set in my OS and set them from grinder on other systems before launching tests.
This also works nice from WebStorm where launch configurations allow to specify environment variables.
This might be related http://dartbug.com/21020
I have the following workaround in the meantime. It is an ugly workaround that gets me the directory name of the current test script if I'm running it directly or with pub run test. It will definitely break if anything in the implementation changes but I needed this desperately...
library test_utils.test_script_dir;
import 'dart:io';
import 'package:path/path.dart';
// temp workaround using test package
String get testScriptDir {
String scriptFilePath = Platform.script.toFilePath();
print(scriptFilePath);
if (scriptFilePath.endsWith("runInIsolate.dart")) {
// Let's look for this line:
// import "file:///path_to_my_test/test_test.dart" as test;
String importLineBegin = 'import "file://';
String importLineEnd = '" as test;';
int importLineBeginLength = importLineBegin.length;
String scriptContent = new File.fromUri(Platform.script).readAsStringSync();
int beginIndex = scriptContent.indexOf(importLineBegin);
if (beginIndex > -1) {
int endIndex = scriptContent.indexOf(importLineEnd, beginIndex + importLineBeginLength);
if (endIndex > -1) {
scriptFilePath = scriptContent.substring(beginIndex + importLineBegin.length, endIndex);
}
}
}
return dirname(scriptFilePath);
}
I want to implement the card scanner from card.io SDK into Phonegap for iOS. I'm using Phonegap v2.9.0 and had went through this https://github.com/card-io/card.io-iOS-SDK-PhoneGap
I understand that it is a plugin, but I haven't created or implemented a plugin in Phonegap before. The code provided in the above link does not work for me. I don't know why, may be I am doing something wrong in the set up steps.
I want a clarification. Below are the steps given in gitHub
1) Add CardIOPGPlugin.[h|m] to your project (Plugins group).
2) Copy CardIOPGPlugin.js to your project's www folder. (If you don't have a www folder yet, run in the Simulator and follow the instructions in the build warnings.)
3) Add e.g. to your html.
See CardIOPGPlugin.js for detailed usage information.
4) Add the following to config.xml, for PhoneGap version 3.0+:
<feature name="CardIOPGPlugin"><param name="ios-package" value="CardIOPGPlugin" /></feature>
My doubts:
Which folder are they talking about in(1)? Plugins folder in Xcode? Or the Plugins folder in Project directory (directory that has config.xml). I have tried both but the sample code does not call the onCardIOCheck.
The gitHub for card.io SDK provides initial setup steps. (https://github.com/card-io/card.io-iOS-SDK)
There, in Step 2, they say "Add the CardIO directory (containing several .h files and libCardIO.a) to your Xcode project." How do I do this? Where do I copy the folder to?
And I have also done step 3 and 4 which are
3) In your project's Build Settings, add -lc++ to Other Linker Flags.
4) Add these frameworks to your project. Weak linking for iOS versions back to 5.0 is supported. (list of frameworks..)
I have done all, my onDeviceReady works, but window.plugins.card_io.canScan(onCardIOCheck); is not calling.
Please.. anyone who has done this before in PhoneGap and iOS, please provide a detailed explanation and steps to implement this in Phonegap iOS.
Providing my code: (app id is changed for question sake)
document.addEventListener("deviceready",onDeviceReady, false);
function onDeviceReady() {
alert('device ready');
var cardIOResponseFields = [
"card_type",
"redacted_card_number",
"card_number",
"expiry_month",
"expiry_year",
"cvv",
"zip"
];
var onCardIOComplete = function(response) {
alert("card.io scan complete");
for (var i = 0, len = cardIOResponseFields.length; i < len; i++) {
var field = cardIOResponseFields[i];
console.log(field + ": " + response[field]);
}
};
var onCardIOCancel = function() {
alert("card.io scan cancelled");
};
var onCardIOCheck = function (canScan) {
alert("card.io canScan? " + canScan);
var scanBtn = document.getElementById("scanBtn");
if (!canScan) {
scanBtn.innerHTML = "Manual entry";
}
scanBtn.onclick = function (e) {
window.plugins.card_io.scan(
"MYAPPIDCHANGEDFORQUESTION",
{
"collect_expiry": true,
"collect_cvv": false,
"collect_zip": false,
"shows_first_use_alert": true,
"disable_manual_entry_buttons": false
},
onCardIOComplete,
onCardIOCancel
);
}
};
window.plugins.card_io.canScan(onCardIOCheck);
}
Which folder are they talking about in(1)? Plugins folder in Xcode? Or the Plugins folder in Project directory (directory that has config.xml). I have tried both but the sample code does not call the onCardIOCheck.
the Plugins folder is the same, Xcode project just references the folder, when you copy files (depending on how you like to organize them) you would usually select copy and hence they will be places in the plugins folder, as long as the files compiled into the project it doesn't really matter.
There, in Step 2, they say "Add the CardIO directory (containing several .h files and libCardIO.a) to your Xcode project." How do I do this? Where do I copy the folder to?
It doesn't matter where you will copy the files as long as they are included in the Xcode project and compiled.
I have done all, my onDeviceReady works, but window.plugins.card_io.canScan(onCardIOCheck); is not calling.
Make sure the CardIOPGPlugin.js is loaded before the javascript files using it, it maybe undefined and hence fails.
Hope it helps.
I have a project with multiple targets. Assume the targets are named Target-A, Target-B and so on. For every target I have a different asset catalog of App Icons. They are named as AppIcon - A, AppIcon - B and it goes on for all the targets. I have assigned respective asset catalogs to all targets, but it only shows the icons for Target-A when i run on the device / simulator. For all other targets it does not set any icons and shows iOS 7 default placeholder icon.
Please help!
If you're using PODs in your project, then you have to edit "Pods-resources.sh" and remove "xcassets" commands (see attached picture).
When you are adding the app icon image please note while adding app icon-1 to Test target then select only test target not Test copy target same for Test copy target.
Also add row for "Icon file" in both the plist and specify your app icon names.
Please check following screen shots you will get some ideas.
The easiest way for me was to add multiple "App Icon" in the same xcassets file. With this technique, I had no problem with Cocoapod :
Open your xcassets file
Right click on the left column
Click "New App icon"
Then you can easily select the correct "App Icon" for each target.
So I wrote a script to delete all those lines which are pointed out by Lukapple.Paste the code to run Script in the xcode project after Target Dependencies.
echo "run script to remove Pods-resources.sh"
file_name="${PROJECT_DIR}/Pods/Target Support Files/Pods/Pods-resources.sh"
function remove_wrapper_extensions {cat "$1" | awk 'BEGIN { suppress_output = 0; } /^if \[\[ -n/ { suppress_output = 1; } (!suppress_output) { print $0; } /^fi$/ { suppress_output = 0; }' > "${1}.1"}
function remove_case_statement {cat "$1" | awk 'BEGIN { suppress_output = 0; } /\s*\*\.xcassets\)$/ { suppress_output = 1; } (!suppress_output) { print $0; } /;;/ && (suppress_output) { suppress_output = 0; }' > "${1}.2"}
remove_wrapper_extensions "$file_name"
remove_case_statement "${file_name}.1"
rm "${file_name}"
rm "${file_name}.1"
mv "${file_name}.1.2" "$file_name"
chmod +x "${file_name}"