Launch installed app on tethered iPhone - iphone

I'm working on trying to launch an automated testing solution for some iOS applications. I'm using fruitstrap to transfer and install a compiled app over to the connected iPhone, but I'm struggling to find a way to automatically launch the application after the installation is complete.
Fruitstrap has an option to run the app in the GDB debugger, which works. Unfortunately there are some test cases which will require the app to be run without the debugger attached (special crash handling). I've spent a good amount of time muddling through the resources available on MobileDevice Library which is what Fruitstrap uses, but I haven't been able to turn anything up on launching an App.
Any ideas?

You can do what you want by using fruitstrap or Xcode to start a "bootstrap" program that causes your target application to run via a custom URL as described by Michael.
While the bootstrap program would be running under the debugger the URL-invoked program would be running normally.

Creating a bootstrap program and using URL Schemes may be an option for some people, and certainly should be considered, but it doesn't fit into my requirements.
What I ended up doing was to launch the app with the debugger through fruitstrap. I re-compiled fruitstrap to include the following prep commands (In the GDB_PREP_CMDS define):
handle all noprint pass nostop
continue
The handle will pass the signal on to the program so the custom signal handler (crash handler in this case) will handle the signal. The continue was something I needed so that the app would actually run once the debugger started.
There is one unfortunate flaw in this, which unfortunately I do not know a workaround for. The ARM7 version of GDB does not have the 'set dont_handle_bad_access' command like the darwin version does. For some reason passing EXC_BAD_ACCESS signals to the program does not work and the app hangs. This is significant since this is the signal for most crashes. But as it stands now, its the best I can do, and at least its handling uncaught exceptions.

I believe you may be looking for some sort of Custom URL Scheme.
Have a look at the following document and scroll down to: Implementing Custom URL Schemes
http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/AdvancedAppTricks/AdvancedAppTricks.html
You can also google URL Schemes in iOS to see if you come across something similar to what you are trying to do.
Let me know if this helped you out. Would be interesting to hear if you had any success.
Cheers.

Related

logs on second run of an ios application in the simulator

I have a question which seems like it should be a fairly common occurrence. I am trying to test code which only runs the first time an ios application is installed. While in principle this is very easy, I'm having trouble with it behaving properly the second time the app runs (note, this is not crash related).
I have been force running the app for a second time using the "Application does not run in background" flag in the plist, and then just hitting the home button. This works great, except i stop getting log data after the first run.
Does anyone know how to test for this situation in a way where you can continue seeing the log information after the app closes? For example, if there is a way to attach the xcode logger to the new process id? Or just another way to force an app reboot without losing the logging feature?
Thanks in advance!
Use the debugger menu:
Product>Attach To Process
(Results may vary with different versions of Xcode).
Also, you might need to insert a sleep at the very start of your launch to catch the very early log messages.
EDIT: If you're on a device then you can use the Device Organizer (cmd+shift+2) to watch all logs on a device.

How can I see the order in which methods and functions are called in my application?

Is there any way in Xcode to see which functions get called in sequence, from start to end? (For example: the main function calls the an app delegate method, and so on.)
Can you do this using breakpoints, or is there another way to achieve this?
Use instrument for that. You can access it from Xcode by asking Xcode to run your application using instrument.
or you can type bt in xCode console
If running in the iPhone Simulator, you can use a custom instrument build with DTrace for doing just that. I provide the code and setup steps for building such an instrument in an article on MacResearch here, or you can just download the custom instrument template here.
This particular template will list, in order of execution, every method called on every class from the launch of your application until it is ready to take user input.
Unfortunately, DTrace does not yet work on the iOS devices, so you can't run a custom instrument like this against your application running there.
(Update 10/4/2011) I propose what is probably a better way of handling this in this answer to a similar question, which uses breakpoints instead of DTrace.

Debugging iPhone App from Command Line

I can do it from XCode, but I want to be able to launch an iPhone App (on the device) from the command line. Is it possible?
Why? Because I want to capture some of the output for semi-automated testing. I'm guessing I need to use a debug build for NSLog output, but I'd also be interested to know about other methods for getting NSLog / stdio data back to the host Mac.
There is a project on github called titanium_mobile (part of Titanium Developer).
I use a utility from that project called iphonesim. It launches an iPhone app from the command line (though I am not sure how, I think there is a way to do that with SpringBoard.app). If you take a step up one level in the Titanium Mobile code and look at builder.py you can see how they launch an app in the simulator and capture the output.
Ultimately I solved my specific need a different way. I needed to get data from the iPhone's accelerometers into a prototype app in Adobe AIR(Flash).
I used this app on the iPhone which drops UDP packets with X,Y,Z forces in them.
http://code.google.com/p/accelerometer-simulator/wiki/Home
Found that from this blog post which might be of interest to people trying to do other similar things.
http://ifiddling.blogspot.com/2009/01/dummy2.html
I used a Python script to present a server to Flash, grab UDP accelerometer packets, munge them into AMF and send them to Flash. Flash uses a socket to connect to this server and receive the accelerometer data.
A few parts, but it works nicely.
You can do this on the device if it is jailbroken. You can put a debug build and symbols on your device and run gdb on it. It is totally unsupported but I hear it works. Not sure if there is a good tutorial. Google?
One method would be to use the AsyncSocket class, and pass whatever data you want to log from the iPhone to a basic host app on the Mac, which NSLogs whatever it receives. If you follow the EchoServer application, you should be able to integrate it in just a few minutes

Running BASH script from iPhone app?

Basically I am wondering if it is possible to run a console script (.sh) from an iPhone App. The script is written to download a program from a repository that I set up, respring, then after a set time delete the program and respring again, so it needs root privileges, and is interactive in that the user can set how long the program will be kept. I have the bash script written, and it works fine when called from mobile terminal, but is there any way to do this from within a (jailbroken) app (without using mobile terminal / SSH / Bossprefs)? Or is there an overall better way to achieve this?
Thanks
Jasarien is right here it is pretty resticted and as we all know that all apps are sandboxed. But it is not impossible since Objective-C is just build on C you can use
system("ls");
to execute a basic ls command and it works if you look in your gdb output. Altho you can also use popen to get the streams to app to work with the data.
Since you're working with a Jailbroken phone, you're pretty much unrestricted. Whether or not there's anything in the iPhone APIs that allows for script execution is another matter though. Also anything you do use will be unsupported, and is likely to change, stop working or be removed in a software update.
Also, you probably already know this, or don't care, but you won't get past Apple's review process for the App Store if you start running BASH scripts. Interpreted code is forbidden.
I would look up how to do it on OSX, chances are that'll be how it's done on the iPhone, but you probably won't find any iPhone specific documentation about it because it's not allowed on a "normal" iphone (one that is not jailbroken)
something you may consider is using NSTask if you want to get output and error messages from the shell.
Actualy
system('ls /'); gives a better result as system('ls');

Debugging j2me on a Device

Has anybody had any success ever attaching a debugger to a tethered device? I am able to debug my j2me application in the emulator, but have a lot of trouble sorting out phone-specific problems when they come up. The phone I'm using is a Nokia N95, but ideally the debug process would work on any phone.
Is this possible? If so does anyone have steps they've used to set it up?
Sony Ericsson supports debugging on ebery phone at least since K700, this is done by using KDWP. UIQ 3 communicators also can be debugged the same way.
By the way, it the latest phones by SE it is even possible to monitor memory consumption and CPU profiling. So if you wanna debug your apps on real phones, I would suggest also using SE phones, they are really good at it. I use Netbeans, and it works without any problems with any SE phone.
Motorola phones support a debugging interface called KDWP(Motodev registration required).Their MIDway tool can also be useful for getting debug trace information from a midlet running on a device.
As other stated, on device debug is something that strictly depends on manufacturer's will and often it's nearly impossible. However, i can address you to Gear Java Mobile Framework that gives you the opportunity to use an on-device debug console to print your messages and thus read phone specific issues. If you need some explanation on how to use it, take a look to this tutorial
Unfortunately this is not generally possible. Some makers (like Sony-Erricson) support this on some of their phones but not all. I am not sure if there is on-device-debugging tool for N95 but you can use Nokia's emulator which should be pretty close to the device. The new Java ME SDK comes with promise of real ODD in near future. But it still very much depends on OEM cooperation.
I find a good debugging method is to control a string value which gets painted on top of everything else when it is not null. This will work anywhere, though obviously isn't ideal, but can be used to catch Exceptions, print values etc. Of course you're limited to the small screen, but in theory you could even code some scrolling functionality.
Some people use RMS logging but personally I could never be bothered.
As others have said here, Motorola have Midway which I think is great.
Others are correct here in that on-device debugging is very much device specific. I haven't done anything with Series 60, but at least on Series 40 phones, I had to open up a CommConnection and write out to it in order to see much of anything going on. The device emulators are again a mixed bag, but you usually can get 90% of the way to your application working on them and can usually get your debugger connected to them. If you aren't making use of any of the hardware on the phone, that should get you most of the way there.
I've used the Blackberry tools on occasion to debug J2ME applications (without using RIM APIs) but it is very slow and still is only emulation, not the actual device (but it sometimes does help to shake the odd thing out). I agree it is frustrating when you have something running on an emulator only to find that it doesn't run on the hardware.
You can not debug step by step like android or other SDK.
In J2ME you can trace the error by adding the log statement in the code and add another midlet and display that log screen in that midlet.
Example: add Log.p("Log statement.....");
LogMidlet.java
// Add the following line in the startup method of this midlet.
Log.getInstance().showLog();
This way you can somehow track the error in j2me.
I think it is possible to add additional debugging information on preprocess step. Like this:
public void myMethod() {
Debug.traceMethod("myMethod");
int var = 1;
Debug.newLine();
var++;
Debug.newLine();
...
}