How can i join an iPad and iPhone app?

I have an iPad app and an iPhone app.

I would like to join them so that if the join app will run on the iPad it would have a behaviour and if it runs on the iPhone it will have another.

The first thing that i thought was to make different views and select the view for the iphone/ipad but i also have some things specific to the ipad and iphone (example : splitViewController) so only selecting a different view won't help.

What is the best way to join 2 such apps ? i would like a more elegant method than doing something like

if(isIPhone)
{
// code for iphone

}
else if(isIPad)
{
// code for iPad

}

every time i have a difference between the 2 versions. Thanks!


I believe that the WWDC 2010 session videos include an iPad Development Overview that covers exactly this issue.

Here's the approach I've taken, according to Apple's guidance:

You can set platform-specific Main Interface nibs, which means you can set platform-specific app delegates as well. So you perhaps have a superclass app delegate that does all your app setup, then subclasses to deploy either an iPad UI or an iPhone UI.

This is helpful since, on the iPad, split views need a traffic cop to determine what content goes where. Now you've got a spot to put that logic independent of the view controllers: in the app delegate.

From there, any time there is a view controller that is common to both platforms but has some specific behavior for each, a view controller superclass is created that handles all common functionality. An iPad-specific subclass might then override the -refreshView: method to do some additional animation, or to add properties and delegate methods to support split views.

While you can definitely test for iPad-ness with if else , this can get really gnarly in a view controller as you add delegate methods that only matter on one platform. By splitting it up this way, you get code that's a lot easier to maintain and read. This can all mean a lot of refactoring of an existing project. In my case, though, it only took about an hour and the result is a very tidy app that's easy to jump in and modify for one or both platforms.


你在找什么是这样的:

if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {
    // Do iPad specific stuff.
} else {
    // Do iPhone/iPod touch stuff here.
}

In XCode 4 at least, you can set which code you want each target to compile, and ignore the rest entirely. So in theory, you could copy all of your iPad app into the iPhone app and then make sure that each only references its own resources and code. The only issue you might run into is naming conflicts, but you can get around this by using groups and folders.

That seems like the simplest way, since you already have both built. The disadvantage with this method is that you will still have to fix bugs in the code separately, but your users will be able to use the same app on their iPhone and iPad.

EDIT:

See BUILD_PHASES > COPY_BUNDLE_RESOURCES & BUILD_PHASES > COMPILE SOURCES

链接地址: http://www.djcxy.com/p/95762.html

上一篇: 检测附近的其他iPhone / iPad

下一篇: 我如何加入iPad和iPhone应用程序?