Compile Command Line Binary for iPhone in Xcode (for Jailbroken iOS) - iphone

I want to compile a tool I've made that runs on my computer to also run on my iPhone through Xcode. I know it's possible but I can't figure it out, does anyone here know how to do this?
I know how to make regular apps I've made work on my Jailbroken iPhone, and I know all about permissions and code signing. I just want to get the code for my command line tool to compile for the iPhone.

For a bash script you could use system:
system ("echo This is bash!")
If it's objective C (Mac) then porting shouldn't be too hard but yes it can be difficult!
If this isn't what you were looking for, your question was WAY to vague.

Related

Jailbroken iPhone dev

I have had great success with running perl on my jailbroken iPhone 4: http://coredev.nl/
Now I would like to play with more functionality like CoreLocation. I'd like to query some GPS and orientation data. I do have OSX running in a VM and so I am able to compile iOS apps in Xcode. However I've been having a difficult time learning the ins and outs so far, and I would really like to have some way of hacking together something more UNIX-y that I'm comfortable with, like the server/client networking perl scripts I have been writing.
For example I can easily download some sample code from Apple, load it up in Xcode, compile after switching off the code signing and whatnot, then SCP the app directory into /Applications, restart springboard, and bam it's on the homescreen, I was really happy to have all of this working (through a virtual machine no less!), but this is actually overkill.
What if I want an executable that I can run from perl, which simply spits some GPS coordinates out on stdout? I understand I'll need to use CoreLocation API, but I shouldn't have to deal with MVC, right?
What about the p5-GPS* packages?
http://coredev.nl/cydia/dists/iphone/main/binary-iphoneos-arm/

what do I type in terminal to compile C code for iphone on mac?

Hey all,
Hoping to compile the "cat" program for iphone4. I figure the command to do so is gcc -somecommandtospecifyiphone. I want to do this on my mac and then just move the file to my iphone later. all compiler errors aside, what command do I type to do this?
Edit:
Provided its not done via gcc or in a terminal or whatever, how would I accomplish this?
What you want to accomplish isn't trivial for a couple of reasons (assuming you haven't jailbroken your iphone). first, each app you install is sandboxed, so you can't really pipe things into cat like you would want. Second, the lower level stuff on iphone is abstracted away, so you can't really bring up a shell and interact with cat. Finally, software on the iphone must be digitally signed. Xcode (the apple IDE) takes care of a lot of this stuff for you, but in the end it is still using gcc to (cross)-compile and install iphone software.
Here are some pointers if you still want to try to get this to work:
- jailbreak your phone so you can install non-codesigned software on it
- specify an arm architecture when compiling with gcc, better yet build your project in xcode and allow it to help you. You can also look into the commandline xcodebuild tool if you really want to stick to the command line.

Running python/ruby script on iPhone?

From the recent news from the Apple, I learned that one has to use C/C++/Objective-C for iPhone App. Accordingly, it's not possible to use MacPython or similar to make iPhone App.
But as the python/ruby interpreter itself is written in C, isn't it OK to make python/ruby interpreter for iPhone to run the scripts on iphone?
Is this possible? Does Apple support this? Or does someone implemented this? Or, the user should hack to do this?
Added
I don't distribute the python script, I just use it for my own utility. Even in this case, do I need a jailbreak? I mean, can I compile the python with Xcode to get the binary? Or, I expect someone has already done this.
Apple recently changed their policy on this and allowed a python interpreter App called Python for iOS to be put up on the App store:
http://itunes.apple.com/us/app/python-for-ios/id485729872?mt=8&uo=4
Full disclosure: I am the sole creator/developer of Python for iOS.
At present not at all. Apple licenses forbid to run any intepreter on it, and this is even before iPhone OS 4. You can make an intepreter by jailbreaking it but it won't be official and you won't be able to distribute it.
I don't distribute the python script, I just use it for my own utility. Even in this case, do I need a jailbreak?
No, you don't. You can compile a Python interpreter and run it on your own iPhone, as long as you have a developer license.
Maybe you can use ad-hoc distribution (according to Apple, you can distribute your app to 100 devices by yourself, outside of the app store) ?
See here

Equivalent to a Flash projector for iPhone?

Is there any equivalent to a Flash projector for iPhone? Flash projectors basically seem to package script and Flash libraries into one executable file that can be run on a PC. I'm wondering if anyone has made a similar thing for iPhone where I can take my existing code and package it with the necessary iPhone stuff to make a PC executable. Of course hardware-specific things would not be available like accelerometer/phone/gps, etc. but I don't need any of those. If not, is there anyone currently attempting this?
Thanks for the input guys, but I think everyone except Noah is misinterpreting my question. Flash was just an example, if you hate Flash just pretend I said something else. I am wondering if it is possible to make code for iPhone run on a PC in a similar way to the way a projector works for Flash.
Right now, the only way to run an iPhone app outside of an iDevice is to compile it from source for a non-iPhone target, so it depends on what you're using to compile. If you're authoring in XCode, you can target the Simulator (which is mac-only), but Apple doesn't currently have a way to compile for any other targets, or a way to compile an object file that runs on Macs without the simulator. If you're authoring in Flash CS5, of course you can just publish a projector.
Not at this time. However, Flash CS5 will create iPhone applications.
Flash is not available on the iPhone.
Furthermore, any company attempting to make a Flash runtime -- which would require doing bytecode interpretation -- would run up against Apple's developer agreement, which specifically forbids that.
I think Adobe is planning for CS5 the export to iPhone app feature. It essentially compiles flash's runtime to Apple's cocoa touch framework and produces a true iPhone app, thus circumventing the bytecode interpretation clause. Time will tell, time will tell...
--- Thanks for the clarification Myz... WTB Noah's reading skills, I thought you had typo'd the PC part due to the outrageousness of your question.
If by PC you mean a windows binary simulator interpreting .ipa files. No, such thing doesn't exist and I don't expect to see it for decades. The platform is much more harder to emulate than the old SNES/N64 and others.

XCode Test Automation For IPhone

I would like to have my iphone test app to be tested automatically in an IPhone. The following are the steps I would like to have:
compile, link and code sign the iphone app (Xcodebuild)
upload the newly built app to iphone
run the uploaded app in iphone automatically
collect the result from the gdb console
close the app
Right now, I have problem with step 2 and 3 where I cannot do it automatically (I can do it from XCode via "Build and Debug" button. This, however, will require manual clicking).
I did some research on automator and it does not answer my problem. Another option I am thinking about is to have the app compiled for iphone simulator and run it from there, but I am not sure how accurate the test result will be comparing to the real device.
I am new to Mac/IPhone development, perhaps someone has a better way of testing this. Any feedback and input are welcome. Thanks.
The comment section does not provide a good way of display the solution properly. Here is the summary of answer.
The task of building IPhone app, uploading and trigger the debug process on IPhone is done via AppleScript. Here is how the AppleScript looks like:
tell application "Xcode"
open "Users:chuan:Desktop:iphone_manual_client:iphone_manual_client.xcodeproj"
tell project "iphone_manual_client"
clean
build
(* for some reasons, debug will hang even the debug process has completed.
The try block is created to suppress the AppleEvent timeout error
*)
try
debug
end try
end tell
quit
end tell
AppleScript accepts ":" instead of "/" for file and folder separator.
The GDB console output can be captured by setting the GDB option to write it to file. this is done by typing the following command in Terminal:
defaults write com.apple.Xcode PBXGDBDebuggerLogToFile YES
defaults write com.apple.Xcode PBXGDBDebuggerLogFileName <path to my gdb output file>
Lastly, many thanks to various ppl who have helped to solve this problem.
The tool you probably want to use for the build and install is Applescript. Something like:
tell application "Xcode" to launch
I'm not pretending that this is a complete answer; there are still a lot of things to work out. But Applescript is going to be one of your key tools I believe.
Check out UISpec http://code.google.com/p/uispec/
It's a full automation test framework being developed for the iphone.
Check out iphone_testify, it works well with OCUnit and Google Toolbox For Mac, and I think it could be possible extend it for something like UISpec.
Regards
There's a command line tool "xcodebuild" you can call to kick off an XCode build without it being open. There are flags you can use to set targets and so on.
Dr Nic's testing with Ruby may help with some of this
Could you add a build phase to the target that runs a script to upload the binary to the iphone?
Right click the target, Add->New Build Phase->New Run Script Build Phase
xcodebuild will just build the binary and it will not upload the newly compiled binary to iphone.
actually it can upload (after signing it), but not run too bad...
maybe it can be run using gdb once connected to target but how (ip?, usb? usbnet?) ?