iOS Unit testing universal application - iphone

I am trying to set up some unit tests on a universal application. The application behaves quite differently when loaded on ipad/iphone. For example there is a separate delegate for each, separate views and controllers as well.
How can I configure a particular test target or particular test files to be tested on iphone/ipad. For example, run TestsTarget1 on iPhone and TestTarget2 on iPad? Can something like this be set on a per-file basis? For example "TestIpadMaps.m" to be run on iPad while "TestIphoneMaps.m" to be run on iphone.
Edit: The reason why I ask is because I want to run tests on certain methods that make reference to the app delegate which is different depending on the device it is being tested on.

You could use an if statement to check if NS (or it could be UI as I'm on my iPad so I don't have reference)device is equal to iPhone and if it is run your test or GoTo your view.
Here is a video that will help
http://www.youtube.com/watch?v=meiv1ePUEnM

Related

Hiding already developed iPad classes in iPhone app

For development reasons, I started developing a universal iOS app, but want to launch with the iPhone version only first.
Besides modifying the “Targeted Device Family” to “iPhone” in the build settings, are there any more necessary steps to prevent users opening the already developed iPad classes/views on their iPad?
Moreover, is there a possibility for users (e.g. with jailbroken devices) to enter the app in iPad mode on their iPad? (How) Can this be prevented?
You can put a condition like :
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
--- do something--
}
and comment out the calls for loading iPad classes and views
The answer to this varies based on how you've set up your existing code. If for example, you perform run time checks for the current hardware E.g if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) and change the UI based on the result of this, then you'll have to redo some code because even if the app only has an interface for iPhones, that condition would still evaluate true on an iPad.
Then another option is to have your classes split between interfaces. This is probably the best method when done right. By that I mean really sticking to the MVC paradigm and making your two interfaces separately, then linking each to its own controller object and then putting as much reusable logic for your app in one universally accessible object somewhere.
If you're done this the second way I've mentioned, you shouldn't have any trouble. Simply by pointing the project toward a storyboard for the iPhone/iPad versions of the project, the correct class files are loaded etc. Which leads me to the direct answer to your question.
Modifying the "Targeted Device Family” is all you really have to do provided you've set up your project in the second way I listed. And furthermore, there shouldn't be any concern that jailbroken users will access the iPad files. They can get in, but they're all compiled anyway and 99% of people don't know what to do with that big blob of gibberish.
And even if they did, I don't think anyone is going out of their way to try to find iPad versions of iPhone only apps. They know that if an app has a completed iPad version, it will just run on their iPad.
you do not need something else besides modifying "Targeted Device Family" property. I see little possibility that launching iPad mode is possible even on jailbreaked devices, but you can, for example, remove iPad files (and dependencies for them) from your project for iPhone build. I still think this is not necessary step.

What is the difference in behaviour testing on the simulator, device and app store

I am trying to figure out what the differences is testing on different layers in regards to accessing the main bundle, documents directory etc.
I know that when testing on the simulator it creates a copy of the execution environment which is separate from xcode. What about on the device and on app store and what is the difference?
The simulator is there as a quick guide. It shouldn't be relied on as the only method of testing. There are differences between the simulator and device (simulator is not case sensitive, for example) and the simulator can't provide all functions as the device (compass, camera for example)
There should be no difference between how your code accesses documents directory, etc between the two. As long as you code the correct way (for example, case sensitively), your code should work on both.
When you release to the AppStore, there should be no difference to what you were running on your device. It is just bundled up and signed with the appropriate certificates.

Is there a global way to merge an iPhone and an iPad app into a universal app?

I wrote an iPhone app. Then, I changed the interface a fair bit, added higher res images, and made an iPad version of it. In a perfect world, I would like for anyone who buys the iPad version to get the iPhone version for free (though not conversely). Since Apple doesn't seem to have a way to do that (right??), my next favorite solution is to make the iPad version include the iPhone version somehow.
I know that I could just convert the iPad version to "universal", but since the face of the app is so different, that seems like a real pain. I have many view controllers and they are almost completely different between the two versions. Some of the methods are the same, but only about 30%. Is there an easy solution along the lines of this:
Check if device is iPhone or iPad
If iPhone, then use one group of files
If iPad, then use a different group of files
Thanks in advance!
Try creating a new project in Xcode and choose to make it a universal app. In the default way Xcode lays it out, there is a distinct divide between the iPad and iPhone versions. You can make the two versions of the app as similar or different as you want.
In addition, you can check which device you are running on at runtime by using UI_USER_INTERFACE_IDIOM(). Currently the two values for this are UIUserInterfaceIdiomPad and UIUserInterfaceIdiomPhone.
The "easy solution" you describe is basically how iOS loads Universal apps.
There's no other real way around it. You'll have to merge your two projects into one again to do what you want.
The first problem will be that some (many?) names of classes will be common between both projects. You can save yourself some pain by using the "Refactor..." functionality in Xcode to change the names of the classes in one project (say, your iPhone app, since it's older) before you merge them together. The second problem will be your Info.plist; you'll need to ensure that the correct "Main nib file base name", the correct supported interface orientations, icon files, and so on are set to correct values for both iPad and iPhone respectively.

Iphone application run in background without backgrounder(Cydia)

Is it possible to write application via cydia to run in background like appsyn? Work with jailbreak device.
Without Backgrounder(Cydia)
Or is it possible to hide icon form springboard and hide arrow(Corelocation)?
i want to run my app like run plist in background.
please help me
Thank(Advance)
Yes, it is possible. In fact, I originally wrote Backgrounder for exactly this purpose; to act as a model for others to use.
You must do two things:
Make certain that you app installs to /Applications/ (and not /var/mobile/Applications).
Create your own UIApplication subclass, and add the following method:
- (void)applicationSuspend {} // Do nothing
However, if you are targetting iOS 4.0 or newer, you should consider using one of Apple's provided multitasking methods.
Also, depending on what you are developing, it might be wiser to create a daemon (or daemon/client) instead.

Whats the best way to create an iPhone and an iPad application simultaneously?

I have an iPhone app that I would like to port over to the iPad, but I would like to have as little duplication as possible.
How do people usually go about doing this?
In xcode can you have different targets for iPhone and iPad and perhaps do some pre-processor checks? Or is it best to simply have two separate projects altogether?
Note, Im NOT talking about running the iPhone app on the iPad, I mean creating a native 3.2 app...
EDIT
So it looks like creating a universal application is the way to go:
http://developer.apple.com/iphone/library/documentation/General/Conceptual/iPadProgrammingGuide/StartingYourProject/StartingYourProject.html#//apple_ref/doc/uid/TP40009370-CH9-SW8
But what I still dont understand is how to select different NIB files based on your current deployment???
Thanks a lot
For minimal duplication, you can use one project, with 2 sets of .nib files, but one set of source code files which include run-time checks for the UIUserInterfaceIdiom differences.
If you want two (or more) apps instead of a Universal app, just create two targets containing only the appropriate .nib files, and #ifdef the run-time check results using a Preprocessor Macro define in each target's Build Settings to force iPhone or iPad idiom only.
The latest (3.2.3) Xcode auto-generates a Universal project which is a great starting point to see how to target iPad and iPhone in one Xcode project.
File > New Project > Window-based Application > Product : Universal