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

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.

Related

Launch installed app on tethered 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.

Bring App to foreground

Is there a way to bring my app to the foreground once a timer runs out? This is for a kiosk-type app that'll display some information at various points during user's session.
This is for an app that will only be installed on our enterprise devices, thus not be submitted to Apple for approval. I am also opening to exploring jailbreak options.
I'd appreciate any help/tips you guys can provide. Thanks.
Yes, you can technically use Xcode for jailbreak development (but you don't have to). If you want your app to be installed outside the normal sandbox, and in /Applications/, then you'd build with Xcode without code signing, fake code sign (or use self-signed certificate), and then copy/install the app to your device, using scp or something similar (maybe have a script for this).
You can google search on tools like "Theos", "Logos", or "iOSOpenDev", too. More here
Also, see this page for information about fake code signing with Xcode.
In terms of bringing an app to the foreground, there's at least a couple ways to handle that:
One would be to use Cydia to install the (free) utility open. With open, you can issue a command line call to open any app, by using its bundle ID (e.g. open com.mycompany.MyAppName). If you want to do this programatically, issue that command within a system() call:
#import <stdlib.h>
int returnCode = system("/usr/bin/open com.mycompany.MyAppName");
Another alternative is to see this answer by #WrightsCS. Make sure to read the comments, too, about where this goes.
Update: in terms of putting your app into the background, you can kill your app completely with either exit(0) or [[UIApplication sharedApplication] terminateWithSuccess]. Or, see this answer for a solution to programmatically simulate a home button press, which will send the app to the background without killing it.
You won't be able to use NSTimer, because timers don't fire while your app is in the background. However, you can use GCD blocks to run your background work, and make the system() call with open to bring you back to the foreground.
See this answer, probably scrolling all the way to the bottom of his post
or look at this similar answer, which was actually posted at the bottom of the question
Jailbroken options for bringing your app to the foreground:
Hook into SpringBoard using MobileSubstrate. You can find classes and methods with promising names, such as [SBApplicationIcon launch] and [SBApplication launch]. Another possibility is using SBSLaunchApplicationWithIdentifier() from the SpringBoardServices private framework.
Options for suspending the app:
You most likely can do this again by using MobileSubstrate to make SpringBoard close a particular app for you. Maybe you can simulate a home button click by calling [SBUIController handleMenuTap] or something similar.

Recording User Actions using Instruments

I've tried looking for a while, but is there a way to record user actions on iphones/iphone simulators for testing with Instruments? Mainly I want to be able to target an app and record whatever user input I enter, then have that be able to play back/get data for that. Thanks!
There are 2 options in Instruments:
1) Use User Interface recorder instrument, that will record mouse move and clicks of the user and allows to replay these. (Unfortunately it seems that Phone Simulator do not expose your app accessibility elements to UI recorder).
2) Simulate interactions with Automation instrument in javascript using UIA classes - useful for writing interface tests for the app or simulating user interactions. You can read intro about using Automation in this blogpost by Alex Vollmer.
FoneMonkey is a promising third party solution, I had that working on a recent project and whilst it wasn't perfect, it does let you record user actions, play them back and so forth. Plus it seems to be open source so you can extend it yourself if required.
There is also the UIAutomation framework in iOS but I have no direct experience with it.
As Roger said, you're going to have to use the UIAutomation framework. Apple's documentation should get you where you need to go. Also, take a look at this.
You have to write the automation in JavaScript. Annoying, I know, but with enough examples in front of you you should be able to pick it up in under an hour.

Designing iPhone/iPad apps for testability

I'm currently using GHUnit and OCMock for testing my app. I'm using them because I like the fact that I can run test code on the actual device.
The way my app is currently designed is that I have some central services and objects available through properties on the app delegate. For example, I've centralised some core data functionality which can be accessed by [UIApplication sharedApplication].coreData.
The problem I've encountered is that in order to run unit tests on the device or simulator, GHUnit uses it's own app delegate which doesn't have these properties. So if a unit triggers code which wants to access them, it fails.
So I'm looking at the design of the app and wondering if I should redesign the way these core facilities are made available. How do you guys design your apps?
One thing I'm considering is extracting this functionality out to a separate object so that I can then use OCMock to simulate it for testing purposes.
Any thoughts?
After thinking about this a while I realised there was a simpler solution. I created a category with the app delegate's interface which applies to the GU Unit app delegate used when running the tests. This way I can get the tests to run and use this category to return OC Mocks when necessary.
And another technique. This time I extended the GH Unit test iPhone app delegate and added the methods and properties I needed. I then modified the main class to call that instead of the original.
Ahhh, so many ways to achieve the same result :-)

How to show related city name according to the incoming call on iPhone?

I want to add something (eg. the related city name) into the UI view when I make a phone call or received a phone call on iPhone. However, I can't figure out a good solution for this idea. Could anyone who has experience on this subject gives me some suggestions?
My currently solution is, try to write an extension based on mobile substrate and hook functions in SpringBoard. So many difficulties existed and following are my current big questions,
How to develop such a extension? I downloaded some examples from google, unfortunately they cann't even be compiled on my toolchain.
I can't figure out which ui view for the related screen I should use to insert my own component. I get header files of SpringBoard via class-dump, but no docs and no comments about its usage. Could someone share his discoveries with me?
How to build a trusted cross-compiling enviroment on leopard? All kinds of confusing errors pop up when I try to build others's codes. I've tried Zdziarski's instrunctions in his book, it works with iPhone OS 1 and can compile common projects with open sdk, but how should I do to make it works when comipiling ms plugins?
Also, is there any other solution to translate my ideas to codes? I start iPhone development one month ago, no experience with cocoa/Obj-C before. So your suggestions are very appriciated.
~ Link Bian (卞林扣)
Email/MSN: linkou.bian#gmail.com
I think you are asking for too much. It wont be possible to manipulate incoming/outgoing call screens. Ethically, that is.
Zdziarski is a hacker and from his book, you will get many undocumented API calls which will make Apple reject your app. Same goes for Erica Sadun's iPhone Developer's Cookbook.
Something that really helped me get dylibs compiled was using SkylarEC's Xcode template and just appended an extension of '.dylib' onto the binary and sshing it into /Library/MobileSubstrate/DynamicLibraries. I suggest hooking SBCallAlert or SBCallAlertDisplay to get the id of the caller which is usually just an NSString. Play around with it a little bit, those are all the visualizing methods of a call. If you put in an nslog in your custom override method, you can view the output in iPhoneConfgurationUtilitie (windows) or the console in Xcode. From there you would most likley need an index of area codes to comare the callers to. I don't believe you can add subviews to the call, on I intercept and reissue the strings for the views already there.
But you know, apple doesn't like this :P
lemme know if this helps