How to pass arguments to an IPA while deploying it on the device?
Asked Answered
A

1

5

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.

Additory answered 30/5, 2014 at 20:35 Comment(6)
Might be a known issue: see github.com/phonegap/ios-deploy/issues/7 - in any case surely the people to ask are the phonegap people.Hevesy
Can you bake these things in at compile time, and just produce different build flavors for testing?Homograft
Have you tried just reading the arguments in your main function? NSProcessInfo should probably contain the same ones but maybe there is a difference.Armin
@Armin Yes. I tried that and the argv was empty.Additory
@jeffamaphone No. I need them to be passed in runtime only.Additory
@Hevesy Thanks a lot. I will forward this query to phonegap developers.Additory
M
9

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.

Marabou answered 28/6, 2016 at 14:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.