Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forcing a Cocoa application to start in 32-bit mode programmatically

I have a Cocoa application that usually runs in full 64-bit mode on any Mac that supports this architecture.

Now I have an external API that is only available as a 32-bit plug-in to be loaded into the main program. This API is for a third-party input device that only a small percentage of my users will ever purchase, but that is important for that small percentage.

My problem is that the program can only use this API if executed in 32-bit mode. The easiest thing to do is of course to:

Scenario 1: ask the user to start the program in 32-bit mode by changing its information via the Finder's Get Info dialog.

This is easily done, but hardly elegant..

Scenario 2: always run in 32-bit mode thus avoiding the problem

Hardly what I want to do either.. penalizing 98% of users for the sake of an exotic feature.

Scenario 3: automatically change the application's launch attributes so that it starts in 32-bit mode next time it is launched and every time afterwards

or

Scenario 4: at launch time, establish which architecture is being used, then re-launch in 32-bit mode if necessary

Scenarios 3 & 4 have the problem that very little is documented on how to do this and it might get me into trouble with the Mac App Store guidelines.

So far, I've established:

  • that using the "arch" command line tool will allow me to restart my executable in 32-bit mode
  • Finder scripting won't let me change the "Launch in 32-bit mode" flag
  • the flag is managed by the Launch Services API (http://blog.timac.org/?p=490)
  • BUT I haven't found any interface to programmatically change the flag in the Launch Services API

So far I can see only these options, none of which seem particularly great:

  1. relaunch the application using NSTask and the "arch" command line tool
  2. write directly into the com.apple.LaunchServices.plist
  3. isolate the 32-bit plug-in into its own 32-bit only process and use IPC

Solution 1 could get me into trouble with the MAS submission. Solution 2 would almost certainly do so at some stage.. only solution 3 would be perfect from a user's perspective but add a huge amount of complexity for minimal pay-off.

Any advice on how to do this "cleanly" and with reasonable effort would be highly appreciated!

like image 530
Frank Avatar asked Aug 15 '11 11:08

Frank


1 Answers

Option 5: Create another executable that always runs as 32 bit and its sole purpose is to drive the 32 bit component in question. Launch that executable from your primary application and use some type of processor independent io to communicate with each other, probably sockets.

like image 79
justin.m.chase Avatar answered Oct 28 '22 17:10

justin.m.chase