This article details the steps taken in creating the iPad port of the libswift library. Attached to this article is a proof-of-concept application.
To build applications for the iPad, the best way is to use a Mac with XCode. You need the (at least) IOS 4 SDK, which will only run on Mac OS X 10.6 (Snow leopard).
To retrieve the libswift code, it is easiest to use git for Mac, for which an installer is available here.
Applications for the iPad are written in Objective-C, and source files use the extension .m. There also exists a variant called Objective-C++, which allows mixing of Objective-C and C++. Files which are to be compiled as Objective-C++ files should have the extension .mm. Therefore, the first thing to do after creating a new project is to rename any files which will call C++ code (i.e. the libswift code) to have the .mm extension.
The next step is to import the libswift source files into the project. Make sure you only import the necessary source files, and not all the tests, documentation, and the .git directory.
To call the libswift library, you need to include the swift.h header file. However, this only works correctly if done in a .mm file, or in a header file which is only included by .mm files. Note that libswift uses its own namespace (swift). So either you have to include a "using namespace swift;" line, or prepend libswift symbols with "swift::".
Networking on the iPad can be done with the standard Unix socket API. All calls like socket, sendto, recvfrom, select, getsockname etc. are available.
Threading on the iPad does not use the POSIX threading interface, but instead uses an Objective-C based threading (see this tutorial). One of the things to be careful about is dead-locks (obviously). Using the NSOperation-based threading, it is very easy to create one. When using the performSelectorOnMainThread method, the last argument is whether to wait for completion. This can be used to prevent race conditions, but can easily lead to dead-lock as well. For example, when cancelling a thread and then waiting for all threads to finish (as is done in stopDownload in the proof-of-concept), also trying to wait for completion of the method called on the main thread will cause a dead-lock.
When using XCode and the iPhone simulator (which also simulates iPads), standard output and standard error are available in the console (Run -> Console). Any uncaught exceptions are also shown here.
- Code is on testmac:/Users/tribler/Documents/*
- Sintel 1024 excerpt (root hash f9cdbb088b3838dad695fd9c7cfe79c73c0035c0):
- Run ./ipad-runseeder.sh from pygmee:/prod/tracker3.p2p-next.org/ipadseed/
- Successfully tested with H264 and AAC in MP4 container:
Duration: 00:11:49.84, start: 0.000000, bitrate: 467 kb/s
Stream #0.0(und): Video: h264, yuv420p, 432x240 [PAR 1:1 DAR 9:5], 366 kb/s, 29.97 fps, 29.97 tbr, 2997 tbn, 5994 tbc
Stream #0.1(eng): Audio: aac, 44100 Hz, mono, s16, 97 kb/s
- sintel 1024 excerpt (just took first N frames from original MP4 Stereo version):
Duration: 00:01:28.83, start: 0.000000, bitrate: 783 kb/s
Stream #0.0(und): Video: h264, yuv420p, 1024x436 [PAR 1:1 DAR 256:109], 587 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc
Stream #0.1(eng): Audio: aac, 48000 Hz, stereo, s16, 190 kb/s
- Build binary for Device:
- official guide
- unofficial tutorial
- Get developer keys
- In Project menu, select Project Settings, then select Build tab
- Scroll down to Code Signing and select right identity
- (Set to Release build?)
- HOWTO: load binary onto device?
- Redeploy app to Device after provisioning profile expired:
- Build & deploy will fail with "Code Sign error: a valid provisioning profile matching the application's Identifier 'com.companyname.appid' could not be found."
- Log into iPhone developer website: http://developer.apple.com/
- Then click on "Provisioning Portal" on the right hand sidebar menu (right at the top).
- On the next page click "Provisioning" in the left sidebar menu
- Then you'll see your provisioning profile/s, and the 'renew' button/s - Press it
- Move to different tab
- Return to provisioning tab
- Press download
- Drag file.mobileprovision to Xcode icon (start Xcode first)
- In Xcode open Organizer from Window menu.
- In "Provisioning Profiles" tab remove old SwarmPlayer3000 (press delete/backspace)
- Connect iPad
- In Organizer open "Tribler iPad" tab under Devices
- Remove SwarmPlayer3000 profile (press delete/backspace)