Reputation: 137
To automate my app, I need to pass some parameters to the built IPA as I deploy it on various devices and run my automation. From various threads I figured I can use "ios-deploy" (https://github.com/phonegap/ios-deploy), a project forked from the fruitstrap project, to successfully deploy an IPA to device via the command line on my terminal. Although ios-deploy documentation suggests it has an option to provide arguments to pass to the app when launching it by using -a
or --args
, it didn't quite work for me. Rather I am not sure how to read these arguments inside the app. I have tried reading from [[NSProcessInfo processInfo] arguments]
as well as NSUserDefaults method (http://perspx.com/archives/parsing-command-line-arguments-nsuserdefaults) and neither are reading the arguments that I am sending to the IPA via ios-deploy -a
. These methods work fine if I am building app on XCode and sending arguments (Edit Scheme->Run->Arguments->Arguments passed on launch).
Can someone who has used ios-deploy provide an example on how to use the -a
option? Or Is there any other way to launch an IPA (after passing arguments) to a device on the CLI.
Upvotes: 5
Views: 3858
Reputation: 4762
I needed this too, so, as I have finally found a solution, I will post it, so that it would be easier to find for everyone.
First, Install http://macappstore.org/ideviceinstaller/
If link is broken - in Terminal:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" < /dev/null 2> /dev/null
brew install ideviceinstaller
Then you can run an already installed app:
idevicedebug run "com.bundle.bundleId" "argument=value" "argument2"
If you have multiple devices connected, provide device UDID for target device:
idevicedebug -u 22296019555853ad916655420ab7596f7a0111 run "com.bundle.bundleId" "argument=value" "argument2"
In your project you then go through all parameters
for(NSString *arg in [[NSProcessInfo processInfo] arguments]){}
But this works on debug versions. If ad-hoc version is installed - can't really launch app (acts like it would have been compiled as ad-hoc from xcode). If debug version is installed - then it all works.
Then there is ios-deploy.
https://github.com/phonegap/ios-deploy
It turns out - they did not intend it to use just to launch app. Each time you need to "install it". (https://github.com/phonegap/ios-deploy/issues/236)
ios-deploy --bundle "/Users/user_name/Desktop/Payload/Device.app" --debug "parameter1,parameter2,parameter_key3=parameter_value3"
(parameters are provided within one string "all_parameters".. how to separate them - up to you.)
Where you encounter the argument string and then you think of a smart way how to deal with it (separate if multiple parameters, etc..)
But also - in ios-deploy case, if ad-hoc version is tested, I experienced problems (app not launching.. crashing etc..) if debug version is used - it's all fine.
Upvotes: 9