开发者

What's a suitable cross-platform methodology for iOS and Mac OS X?

There seem to be lots of answers for cross-platform frameworks for devices (iPhone + Android), and cross-platform frameworks for desktops (Mac + Win + Linux). This is a different question regarding a su开发者_运维技巧itable framework, methodology, template app, tutorial, or just helpful hints, on developing native apps (not just web apps) that are cross-platform portable between a device OS and a desktop OS.

I want to write a app that can run on both my iPhone (or iPad) and also be compiled to run natively on Mac OS X (and not just run in the Simulator). I am willing to live with only basic UI elements that are common to both platforms (only 1 window, generic buttons, textfields, etc.)

What's the best methodology to build a pair of apps, with the minimum number of #ifdef's and other platform specific code rewrites, that will run on my iPhone and natively on my MacBook?


There is no easy way to do this using standard UI controls. AppKit and UIKit are completely different animals. Even the basic UIView and NSView are very different in structure and function. At that level, you won't see anything that could be made cross-platform.

However, there are display elements that can be made to work on Mac and iOS with minimal changes. Core Animation CALayers are one such element, in that they are the same on Mac OS X and iOS. This is why we chose to use them as the basis for the Core Plot framework, which uses an almost identical codebase to display graphs on Mac and iOS. There are a few platform-specific things to tweak (like the inverted coordinate system a UIView applies to its backing layer), but most of the code will translate to both platforms.

You mention writing a game. If you are using OpenGL ES for this, much of the rendering code you write will also work on the Mac. There are a few things you will need to alter, but for the most part OpenGL ES is a subset of desktop OpenGL. However, for a simple 2-D game I'd recommend sticking with Core Animation unless you really hit a brick wall, performance-wise, simply because you will write so much less code.

The items I've mentioned so far have all been in the View portion of the Model-View-Controller design pattern. Your controller code will be application-specific, but you may be able to make most of that platform-independent. If you use a simple model, or even one that relies on SQLite or Core Data for persistence, that should be trivial to make work on Mac and iOS with the same code.

A Mac application and an iOS one (even between the various iOS devices) will have a very different core design. You can't just shoehorn something from one platform into another. Games are probably more portable than anything else, but you will still need to do some custom work to reflect the unique attributes of each computing device.


I'm also struggling with this one; I'm using Unity3D and the free license doesn't allow native OS X plug-ins.

I've just spent the last hour reading through http://rayvinly.com/how-to-build-a-truly-universal-framework-for-ios-and-mac-with-just-a-single-codebase/

Ray has done a super presentation, you can download his 30 page ebook document! He also provides a template project.

I'm thinking I could use this setup to create a single drawing surface (so, a single window on both platforms) which I could draw to using SpriteKit.

Then wrap mouse/touch input to create a unified input.

As for ready-made frameworks, http://chameleonproject.org/ looks interesting.

http://kivy.org/#home looks much more interesting: multiplatform Python wrapping GLES2

Also http://polycode.org/ http://qt-project.org/

What did you choose in the end?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜