Xcode Development Codesigning Issue - xcode

I recently transferred an app from one account to another. I can submit the app to the App Store and run it in the simulator. However, when I try to run it on my device I get this error:
CodeSign /Users/floydresler/Library/Developer/Xcode/DerivedData/App_for_Dark_Tower-egxiflrzexibnghkjwvtznkhigek/Build/Products/Debug-iphoneos/App\ for\ Dark\ Tower.app
cd "/Users/floydresler/Source Code/App for Dark Tower"
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "iPhone Developer: Floyd Resler (6UFPUB2SE5)"
Provisioning Profile: "Dark Tower Dev"
(31912d69-5ec4-4740-a696-81ea06d3f3fb)
/usr/bin/codesign --force --sign 4EA262133AD193D1EB339D5E39FC055053663735 --entitlements
/Users/floydresler/Library/Developer/Xcode/DerivedData/App_for_Dark_Tower-egxiflrzexibnghkjwvtznkhigek/Build/Intermediates/App\ for\ Dark\ Tower.build/Debug-iphoneos/App\ for\ Dark\ Tower.build/App\ for\ Dark\ Tower.app.xcent --timestamp=none
/Users/floydresler/Library/Developer/Xcode/DerivedData/App_for_Dark_Tower-egxiflrzexibnghkjwvtznkhigek/Build/Products/Debug-iphoneos/App\ for\ Dark\ Tower.app
/Users/floydresler/Library/Developer/Xcode/DerivedData/App_for_Dark_Tower-egxiflrzexibnghkjwvtznkhigek/Build/Products/Debug-iphoneos/App for Dark Tower.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
I have tried cleaning, deleting derived data, recreating the development provisioning profile and nothing works. What am I doing wrong>

A common cause of xcode CodeSign failing with "resource fork, Finder information, or similar detritus not allowed" is additional file attributes being set, often on PNG images.
*** Before proceeding back all your files up, twice, then again, never run batch commands on your project that you dont understand.
You can clean your PNGs with:
find /Users/You/Project -name "*png" -exec xattr -v -c '{}' \;
You can repeat this for all project files with:
find /Users/You/Project -exec xattr -v -c '{}' \;
You can choose just to run this on the built project rather than your source by running it on the directory listed with the error, eg If the error is:
/Users/me/Library/Developer/Xcode/DerivedData/Project-ervhbywkvwhcpnguqaezmqqsbiqe/Build/Products/Debug/My.app: resource fork, Finder information, or similar detritus not allowed
Run:
find /Users/me/Library/Developer/Xcode/DerivedData/Project-ervhbywkvwhcpnguqaezmqqsbiqe/Build/Products/Debug/My.app -exec xattr -v -c '{}' \;

Related

how can I alter permissions in a bash script for application installation

I have two builds of an application that I'm building into a .pkg for distribution using WhiteBox "packages".
The first one works fine but the second one doesn't. There are basically two difference between them - the second version is packaged with eight audio files, and a third-party tool.
The first one installs fine and I have no problems with permissions on an M1 Mac, the second one does not have microphone permissions, but it does have file permissions.
I tried different variations of the following script:
# Set the path to the app
app_path="Applications/[my app name].app"
# Check if the user is running the script as root
if [ "$EUID" -ne 0 ]
then echo "Please run as root or with sudo"
exit
fi
# Generate audio permissions for the app
sudo tccutil reset Microphone "[my.bundle.identifier]"
sudo xattr -r -d com.apple.quarantine " /Applications/[my app name].app"
sudo xattr -rc /Applications/[my app name].app
exit 0
where each individual sudo command was tested independently, then different combinations of them were all tested but none work. The app will also not appear in the 'security' section of 'system preferences'.
The app does work when I package it in a .dmg, with the installer:
clear
echo -e "\033[0;31m"Installer is running ...
mv /Volumes/[installer name]/[my app name].app /Applications/[my app name].app;
open /Volumes/[my app name]/disclaimer.png
(sleep 1 && xattr -rc /Applications/[my app name].app;)
echo -e "Installation is finished... Enjoy [my app name]"
(Sleep 2)
killall Terminal
So I realised that the script is the problem, but I'm not really sure why one works and the other doesn't. I tried directly running the installer as a .sh file in the 'packages' build but it didn't work either.
I was wondering if anyone knew anything? Thanks!
I was expecting to give permissions to the use of audio by my application, but this didn't work

What is the most efficient way to notarize and staple a .zip containing a .app?

Currently, an .app/ folder can't be submitted for notarization and must be packaged first. On the other hand, a ticket can't be stapled to a .zip after notarization is successful. Apple Documentation
This creates a process as below:
Build the application
Zip the .app/
Submit the .zip for notarization
Unzip the the .zip
Staple the ticket to the .app/
Re-zip the .app/ for distribution
Our specific use case is that our application will initially be installed by users from a .dmg while subsequent updates are downloaded through .zip. Notarizing the .dmg is very straightforward. Zipped contents are another story.
Is there a more efficient method than the steps above?
No Dan, you've got it. Your use case is similar to mine and that's how I do it. In my case I'm distributing a .pkg that comprises an app, an uninstaller, a couple of kernel extensions, but the concept is the same for just an app. By the way, like your dmg, I'm distributing the pkg for downloads but then zipping that pkg for Sparkle updates.
The process only seems bizarre until you think of the zip file as a way of packaging and submitting the app bundle. You want to notarize the app and staple the resulting notarization to the app bundle. You do it like this:
Notarize the app by submitting a zipped package of the app bundle.
When the notarization successfully completes, staple the result to the app bundle.
Package the app bundle for distribution (in your case by adding it to a dmg).
Notarize the dmg, and staple to the dmg.
For more convenience: if you do this in a makefile, the make can automatically wait for the notarizations before stapling. I do it like this:
notarizationRequestID=$(shell xcrun altool --notarize-app \
--primary-bundle-id com.mycompany.appID \
--username $(DEV_USERNAME)
--password $(DEV_PASSWORD)
--asc-provider $(DEV_PROVIDER) \
--file myApp.app.zip \
| awk '/RequestUUID/ { print $$NF; }') ;\
while ! xcrun altool --notarization-info $$notarizationRequestID \
--username $(DEV_USERNAME)
--password $(DEV_PASSWORD)
--asc-provider $(DEV_PROVIDER) \
--output-format xml \
| grep -q 'https://osxapps-ssl.itunes.apple.com/itunes-assets' ;\
do sleep 5 ;\
echo "." ;\
done ;\
If you're distributing an update via Sparkle, you'll also need to gather the app cast metadata so you can paste it into your app cast.xml. At the end of the makefile:
#echo "——————————————————————————————————"
#echo " Results for Sparkle Update XML "
#echo "——————————————————————————————————"
#echo
#echo "version: " `defaults read myApp.app/Contents/Info CFBundleVersion`
#echo "shortVersionString:" `defaults read myApp.app/Contents/Info CFBundleShortVersionString`
#echo "dsaSignature: " `$MyAppSource/Libraries/Sparkle/bin/sign_update myAppInstaller.pkg.zip $MyAppSource/Resources/UpdateSigningKeys/dsa_priv.pem`
#echo "length: " `stat -f%z "myApp.pkg`

Run time error in Castalia

Hey friends i had installed Omnet++ 4.2.2 and Castalia 3.2.I had tried to run the example simulations,but it saying an run time error.i had attached it as a image.Please help me.Please tell me the solutions.Help indeed please.
You probably didn't build the Castalia. In order to build it under Windows do the following:
Open in any text editor the file makemake from main Castalia-3.2 directory, and change the line: OPTS=" -f -r --deep -o CastaliaBin -u Cmdenv -P $ROOT -M release" into:
OPTS=" -f -r --deep -P $ROOT -M release"
Open console mingwenv.cmd.
Change directory to the Castalia directory. Example: assuming that Castalia-3.2 is in d:\Castalia-3.2 you should type: cd /d/Castalia-3.2
Then type in mingwcmd console:
./makemake
make
In order to check it try to start a simulation by typing in console:
cd Simulations/BANtest/
../../Castalia-3.2.exe
The simulation should start in graphical mode.

How to trace system calls of a program in Mac OS X?

The bounty expires in 6 days. Answers to this question are eligible for a +50 reputation bounty.
Charlie Parker is looking for a more detailed answer to this question:
suggested answer didn't work, error:
Suggested accepted answer doesn't work for me. This is what I tried:
cd ~ cp /usr/bin/find find codesign --remove-signature ./find sudo dtruss ./find … error:
codesign --remove-signature ./find sudo dtruss ./find dtrace: system integrity protection is on, some features will not be available dtrace: failed to execute ./find: Could not create symbolicator for task
I wanted to trace the system calls made by the find command to debug some performance issues however I could not figure out how to do this on Mac OS X Yosemite. How can I trace system calls for an arbitrary program similarly to what strace does on FreeBSD? I am especially interested in tracing file-system related calls.
Suggested accepted answer doesn't work for me. This is what I tried:
cd ~
cp /usr/bin/find find
codesign --remove-signature ./find
sudo dtruss ./find …
error:
codesign --remove-signature ./find
sudo dtruss ./find
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to execute ./find: Could not create symbolicator for task
Under current versions of macOS, executables under paths covered by SIP (like /usr/bin) cannot be traced.
You can bypass this by making a copy of the executable in your home directory and tracing the copy:
cp /usr/bin/find find
codesign --remove-signature ./find
sudo dtruss ./find …
You needed to remove the code signature from the new find executable, otherwise SIP still notices that a system file is being accessed (credit: #Anmol Singh Jaggi).
You can use dtruss like in
sudo dtruss find ~/repo -depth 2 -type d -name '.git'
The manual page of that utility will help you to tailor the use of the tool to your needs.

Running UIAutomation scripts from Xcode

Did anyone succeed in setting up automated UIAutomation tests in Xcode?
I'm trying to set up a target in my Xcode project that should run all the UIAutomation scripts I prepared. Currently, the only Build Phase of this target is this Run Script block:
TEMPLATE="/Applications/Xcode.app/Contents/Applications/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"
MY_APP="/Users/Me/Library/Application Support/iPhone Simulator/6.0/Applications/564ED15A-A435-422B-82C4-5AE7DBBC27DD/MyApp.app"
RESULTS="/Users/Me/Projects/MyApp/Tests/UI/Traces/Automation.trace"
SCRIPT="/Users/Me/Projects/MyApp/Tests/UI/SomeTest.js"
instruments -t $TEMPLATE $MY_APP -e UIASCRIPT $SCRIPT -e UIARESULTSPATH $RESULTS
When I build this target it succeeds after a few seconds, but the script didn't actually run. In the build log I get these errors:
instruments[7222:707] Failed to load Mobile Device Locator plugin
instruments[7222:707] Failed to load Simulator Local Device Locator plugin
instruments[7222:707] Automation Instrument ran into an exception while trying to run the script. UIATargetHasGoneAWOLException
+0000 Fail: An error occurred while trying to run the script.
Instruments Trace Complete (Duration : 1.077379s; Output : /Users/Me/Projects/MyApp/Tests/UI/Traces/Automation.trace)
I am pretty sure, that my javascript and my run script are both correct, because if I run the exact same instruments command in bash it works as expected.
Could this be a bug in Xcode?
I finally found a solution for this problem. It seems like Xcode is running the Run Scripts with limited rights. I'm not entirely sure, what causes the instruments command to fail, but using su to change to your user will fix it.
su $USER -l -c <instruments command>
Obviously, this will ask you for your password, but you can't enter it when running as a script. I didn't find a way to specify the password for su, however if you run it as root, you don't have to specify one. Luckily sudo can accept a password via the pipe:
echo <password> | sudo -S su $USER -l -c <instruments command>
If you don't want to hardcode your password (always a bad idea), you could use some AppleScript to ask for the password.
I posted the resulting script below. Copy that to a *.sh file in your project and run that script from a Run Script.
#!/bin/bash
# This script should run all (currently only one) tests, independently from
# where it is called from (terminal, or Xcode Run Script).
# REQUIREMENTS: This script has to be located in the same folder as all the
# UIAutomation tests. Additionally, a *.tracetemplate file has to be present
# in the same folder. This can be created with Instruments (Save as template...)
# The following variables have to be configured:
EXECUTABLE="TestApp.app"
# Optional. If not set, you will be prompted for the password.
#PASSWORD="password"
# Find the test folder (this script has to be located in the same folder).
ROOT="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Prepare all the required args for instruments.
TEMPLATE=`find $ROOT -name '*.tracetemplate'`
EXECUTABLE=`find ~/Library/Application\ Support/iPhone\ Simulator | grep "${EXECUTABLE}$"`
SCRIPTS=`find $ROOT -name '*.js'`
# Prepare traces folder
TRACES="${ROOT}/Traces/`date +%Y-%m-%d_%H-%M-%S`"
mkdir -p "$TRACES"
# Get the name of the user we should use to run Instruments.
# Currently this is done, by getting the owner of the folder containing this script.
USERNAME=`ls -l "${ROOT}/.." | grep \`basename "$ROOT"\` | awk '{print $3}'`
# Bring simulator window to front. Depending on the localization, the name is different.
osascript -e 'try
tell application "iOS Simulator" to activate
on error
tell application "iOS-Simulator" to activate
end try'
# Prepare an Apple Script that promts for the password.
PASS_SCRIPT="tell application \"System Events\"
activate
display dialog \"Password for user $USER:\" default answer \"\" with hidden answer
text returned of the result
end tell"
# If the password is not set directly in this script, show the password prompt window.
if [ -z "$PASSWORD" ]; then
PASSWORD=`osascript -e "$PASS_SCRIPT"`
fi
# Run all the tests.
for SCRIPT in $SCRIPTS; do
echo -e "\nRunning test script $SCRIPT"
COMMAND="instruments -t \"$TEMPLATE\" \"$EXECUTABLE\" -e UIASCRIPT \"$SCRIPT\""
COMMAND="echo '$PASSWORD' | sudo -S su $USER -l -c '$COMMAND'"
echo "$COMMAND"
eval $COMMAND > results.log
SCRIPTNAME=`basename "$SCRIPT"`
TRACENAME=`echo "$SCRIPTNAME" | sed 's_\.js$_.trace_g'`
mv *.trace "${TRACES}/${TRACENAME}"
if [ `grep " Fail: " results.log | wc -l` -gt 0 ]; then
echo "Test ${SCRIPTNAME} failed. See trace for details."
open "${TRACES}/${TRACENAME}"
exit 1
break
fi
done
rm results.log
It seems as though this really might be an Xcode problem; at any rate, at least one person has filed a Radar report on it. Someone in this other thread claims you can work around this exception by disconnecting any iDevices that are currently connected to the computer, but I suspect that does not apply when you're trying to run the script as an Xcode target.
I would suggest filing a Radar report as well; you may get further details on the issue from Apple, or at least convince them that many people are having the problem and they ought to figure out what's going on.
Sorry for a not-terribly-helpful answer (should have been a comment, but comments and links/formatting do not mix very well). Please update this question with anything you find out on the issue.
Note: this is not a direct answer to the question, but it is an alternative solution to the underlying problem.
While searching for in-depth information about UIAutomation, I stumbled across a framework by Square called KIF (Keep it functional). It is a integration testing framework that allows for many of the same features as UIAutomation, but the great thing about is is that you can just write your integration tests in Objective-C.
It is very easy to setup (via CocoaPods), they have good examples too, and the best thing is that it's a breeze to set up with your CI system like Jenkins.
Have a look at: http://github.com/square/KIF
Late to the game but I have a solution that works for Xcode 5.1. Don't know if that's what broke the above solution or not. With the old solution I was still getting:
Failed to load Mobile Device Locator plugin, etc.
However, this works for the release version of Xcode 5.1.
echo <password> | sudo -S -u username xcrun instruments
Notice I removed the unneeded su command and added the xcrun command. The xcrun was the magic that was needed.
Here is my complete command:
echo <password> | sudo -S -u username xcrun instruments\
-w "iPhone Retina (3.5-inch) - Simulator - iOS 7.1"\
-D "${PROJECT_DIR}/TestResults/Traces/Traces.trace"\
-t "${DEVELOPER_DIR}/Instruments.app/Contents/PlugIns/AutomationInstrument.bundle/Contents/Resources/Automation.tracetemplate"\
"${BUILT_PRODUCTS_DIR}/MyApp.app"\
-e UIARESULTSPATH "${PROJECT_DIR}/TestResults"\
-e UIASCRIPT "${PROJECT_DIR}/UITests/main.js"
By the way if you type:
instruments -s devices
you will get a list of all the supported devices you can use for the -w option.
Edit: To make this work for different people checking out the project replace the following:
echo <password> | sudo -S -u username xcrun instruments
with
sudo -u ${USER} xcrun instruments
Since you are just doing an sudo to the same user no password is required.
Take a look at this tutorial that explains how to have Automated UI testing with Jenkins. It also uses Jasmine in the tutorial though. http://shaune.com.au/automated-ui-testing-for-ios-apps-uiautomation-jasmine-jenkins/ hope this helps. It has an example project file so you can download that as a template. Hope this helps.
In XCode - if you load up organizer (XCode->Window->Organizer)
Then select your machine under devices -> 'Enable Developer Mode'
This should remove the need for prompts with instruments.

Resources