| @@ -1,9 +1,3 @@ |
| 1 | --- | | |
| 2 | categories: | | |
| 3 | - "Mac OS X" | | |
| 4 | - "IOS" | | |
| 5 | --- | | |
| 6 | | | |
| 7 | ::tpl[Platform only]{1="iOS" 2="iOS" 3="iOS"} | 1 | ::tpl[Platform only]{1="iOS" 2="iOS" 3="iOS"} |
| 8 | | 2 | |
| 9 | ::tpl[iPhone iPod development] | 3 | ::tpl[iPhone iPod development] |
| @@ -13,7 +7,7 @@ |
| 13 | Requirements: | 7 | Requirements: |
| 14 | | 8 | |
| 15 | - Intel Mac (iPhone SDK requirement) | 9 | - Intel Mac (iPhone SDK requirement) |
| 16 | - Mac OS X 10.5.5 or later (iPhone SDK requirement) | 10 | - Leopard 10.5.5 or later (iPhone SDK requirement) |
| 17 | - iPhone SDK 3.x or later installed (tested with 2.2 - 5.1). **Warning:** there is a bug in the iPhone SDK 3.0 linker. See below for more information. | 11 | - iPhone SDK 3.x or later installed (tested with 2.2 - 5.1). **Warning:** there is a bug in the iPhone SDK 3.0 linker. See below for more information. |
| 18 | | 12 | |
| 19 | Some features: | 13 | Some features: |
| @@ -42,12 +36,14 @@ |
| 42 | | 36 | |
| 43 | ## Apple's Licence limitations | 37 | ## Apple's Licence limitations |
| 44 | | 38 | |
| 45 | ### Developing applications for iPhone/iPod | 39 | ### Signing up to the Apple Developer Program |
| 46 | | 40 | |
| 47 | FPC cannot work around the requirement of needing an Apple-issued certificate to run self-written programs on an iPhone/iPod Touch. So you have to sign up to Apple's iPhone Developer program ($99/year) to run FPC-compiled programs on the real hardware (just like for regular Xcode-compiled programs). | 41 | You will eventually need to sign up to Apple's iPhone Developer program ($99/year) to distribute your programs through the Apple store. This applies to any iPhone application, compiled with FPC or not. |
| 48 | | 42 | |
| 49 | Without such a certificate, you can only run programs on the simulator (possibly unless you have a jailbroken iPhone/iPod Touch, but in that case you are on your own). | 43 | You *do not need to pay the fee* to run applications on your own physical iPhone device. A free developer account will be enough for this, if you use the new XCode versions. |
| 50 | | 44 | |
| | 45 | Without a developer certificate, you can only run programs on the simulator. (Possibly you can also workaround this if you have a jailbroken iPhone/iPod Touch, but in that case you are on your own.) |
| | 46 | |
| 51 | Read more about Apple's iPhone development program here: <http://developer.apple.com/iphone/program/> | 47 | Read more about Apple's iPhone development program here: <http://developer.apple.com/iphone/program/> |
| 52 | | 48 | |
| 53 | ### Pascal headers required for developing | 49 | ### Pascal headers required for developing |
| @@ -60,9 +56,9 @@ |
| 60 | | 56 | |
| 61 | ### iPhone Simulator is not iPhone | 57 | ### iPhone Simulator is not iPhone |
| 62 | | 58 | |
| 63 | The iPhone Simulator makes the iPhone OS API in available to regular Mac applications, thereby mimicking the environment that the devices provide. By allowing you to run your applications in Mac OS X, the simulator provides a way to quickly test your application’s functionality without the need for an actual device. However, running applications on the simulator is not the same as running them on devices. | 59 | The iPhone Simulator makes the iPhone OS API in available to regular Mac applications, thereby mimicking the environment that the devices provide. By allowing you to run your applications in macOS, the simulator provides a way to quickly test your application’s functionality without the need for an actual device. However, running applications on the simulator is not the same as running them on devices. |
| 64 | | 60 | |
| 65 | The simulator uses Mac OS X versions of the low-level iPhone OS frameworks instead of the versions that run on devices. In general, the simulator is a good tool for performing initial testing of your application. Keep however in mind that, because the simulator does not emulate device functionality, you must always perform final testing and performance analysis of your application on actual devices. The main reason is that programs running under the simulator can also transparently use any other frameworks/functionality used by the host Mac OS X operating system, which may not be available on the device. | 61 | The simulator uses macOS versions of the low-level iPhone OS frameworks instead of the versions that run on devices. In general, the simulator is a good tool for performing initial testing of your application. Keep however in mind that, because the simulator does not emulate device functionality, you must always perform final testing and performance analysis of your application on actual devices. The main reason is that programs running under the simulator can also transparently use any other frameworks/functionality used by the host macOS operating system, which may not be available on the device. |
| 66 | | 62 | |
| 67 | ## Compiling and running pure Pascal applications on an iPhone/iPod Touch | 63 | ## Compiling and running pure Pascal applications on an iPhone/iPod Touch |
| 68 | | 64 | |
| @@ -86,35 +82,35 @@ |
| 86 | | 82 | |
| 87 | **for FPC 2.6.0:** | 83 | **for FPC 2.6.0:** |
| 88 | | 84 | |
| | 85 | ```text |
| | 86 | ppcarm -Cparmv6 -Cfvfpv2 -FD/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk program.pas |
| 89 | ``` | 87 | ``` |
| 90 | ppcarm -Cparmv6 -Cfvfpv2 -FD/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk program.pas | | |
| 91 | ``` | | |
| 92 | | 88 | |
| 93 | for iPhoneSimulator ( OS_TARGET has been introduced) | 89 | for iPhoneSimulator ( OS_TARGET has been introduced) |
| 94 | | 90 | |
| | 91 | ```text |
| | 92 | ppc386 -Tiphonesim -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk program.pas |
| 95 | ``` | 93 | ``` |
| 96 | ppc388 -Tiphonesim -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk program.pas | | |
| 97 | ``` | | |
| 98 | | 94 | |
| 99 | **prior to FPC 2.6.0:** | 95 | **prior to FPC 2.6.0:** |
| 100 | | 96 | |
| | 97 | ```text |
| | 98 | ppcarm -FD/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk program.pas |
| 101 | ``` | 99 | ``` |
| 102 | ppcarm -FD/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin -XR/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk program.pas | | |
| 103 | ``` | | |
| 104 | | 100 | |
| 105 | for iPhoneSimulator | 101 | for iPhoneSimulator |
| 106 | | 102 | |
| | 103 | ```text |
| | 104 | ppc386 -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk program.pas |
| 107 | ``` | 105 | ``` |
| 108 | ppc388 -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk program.pas | | |
| 109 | ``` | | |
| 110 | | 106 | |
| 111 | ## Compiling and running pure Pascal applications on iPhone simulator | 107 | ## Compiling and running pure Pascal applications on iPhone simulator |
| 112 | | 108 | |
| 113 | Compiling and linking requires a regular ppc386 compiler. There is little difference between an iPhone Simulator and a regular Mac OS X application, except that iPhoneSim applications are linked to different frameworks compared to regular Mac OS X applications. | 109 | Compiling and linking requires a regular ppc386 compiler. There is little difference between an iPhone Simulator and a regular macOS application, except that iPhoneSim applications are linked to different frameworks compared to regular macOS applications. |
| 114 | | 110 | |
| 115 | Starting with FPC 2.6.0 **iphonesim** target has been introduced. For SDKs 3.2 and higher fpc packages needs to be compiled for iphonesim target ([see #17470](http://bugs.freepascal.org/view.php?id=17470)). Reasoning: while FPC compile is still pretty much the same (i386 target), different Objective-C ABI is used. For darwin-i386 FPC is using ObjC1 (to be compatible with OSX 10.4 and earlier), while iphonesim-i386 required ObjC2 only. (It seems like previous versions of iPhoneSim SDK 2.x and 3.0 allows ObjC1) | 111 | Starting with FPC 2.6.0 **iphonesim** target has been introduced. For SDKs 3.2 and higher fpc packages needs to be compiled for iphonesim target ([see #17470](http://bugs.freepascal.org/view.php?id=17470)). Reasoning: while FPC compile is still pretty much the same (i386 target), different Objective-C ABI is used. For darwin-i386 FPC is using ObjC1 (to be compatible with OSX 10.4 and earlier), while iphonesim-i386 required ObjC2 only. (It seems like previous versions of iPhoneSim SDK 2.x and 3.0 allows ObjC1) |
| 116 | | 112 | |
| 117 | Some frameworks are iPhone-specific (UIKit), other frameworks exist for both Mac OS X and the iPhoneOS (CoreFoundation, CoreGraphics, etc). The iPhoneSim SDK provides its own versions of these frameworks. In order to ensure that the SDK's versions of these frameworks are used, you have to to tell the compiler to use appropriate SDK (just like when compiling applications for a real device): | 113 | Some frameworks are iPhone-specific (UIKit), other frameworks exist for both macOS and the iOS (CoreFoundation, CoreGraphics, etc). The iPhoneSim SDK provides its own versions of these frameworks. In order to ensure that the SDK's versions of these frameworks are used, you have to to tell the compiler to use appropriate SDK (just like when compiling applications for a real device): |
| 118 | | 114 | |
| 119 | ``` | 115 | ``` |
| 120 | fpc simtest.pas -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk | 116 | fpc simtest.pas -XR/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.0.sdk |
| @@ -154,6 +150,33 @@ |
| 154 | | 150 | |
| 155 | (possibly with an INSTALL_PREFIX=xyz at the end of the "sudo make" line to install it under "xyz" rather than under /usr/local -- in that case, also adjust the "ln" command afterwards) | 151 | (possibly with an INSTALL_PREFIX=xyz at the end of the "sudo make" line to install it under "xyz" rather than under /usr/local -- in that case, also adjust the "ln" command afterwards) |
| 156 | | 152 | |
| | 153 | ## iOS 8.0 and later |
| | 154 | |
| | 155 | Apple requires everyone to use 64-bit applications for iOS 8.0 (and later). Also iPhone Simulator for iOS 8.0 is 64-bit only. |
| | 156 | |
| | 157 | Whenever you compile a project you'll need to use the proper SDK and proper bin utilities. Note that for iPhone Simulator, there's also its own set of bin utilities, not compatible with default macOS bin utilities. |
| | 158 | |
| | 159 | Example |
| | 160 | |
| | 161 | ``` |
| | 162 | export SDK_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk |
| | 163 | export BIN_PATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ |
| | 164 | ``` |
| | 165 | |
| | 166 | ``` |
| | 167 | ppcx64 -Tiphonesim -Px86_64 -Scghi -O1 -va -XR$SDK_PATH -FD$BIN_PATH iphoneproj.pas |
| | 168 | ``` |
| | 169 | |
| | 170 | Note that using "-va" parameter (show all messages) which helps to know whether you're using the right path for bin utilities and SDK. The desired result is that ctrl.o library and ld tool are found in a proper target platform, similar to shown below. |
| | 171 | |
| | 172 | ``` |
| | 173 | [0.437] Linking iphoneproj |
| | 174 | [0.481] Searching file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk/usr/lib/crt1.o... found |
| | 175 | [0.481] Searching file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ld... found |
| | 176 | ``` |
| | 177 | |
| | 178 | If the path is not found then FPC will fallback to system-wide defaults (macOS target) and the linking is likely to fail. |
| | 179 | |
| 157 | ## More information | 180 | ## More information |
| 158 | | 181 | |
| 159 | - [Simple iPhone example using FreePascal and SDL](http://freeze-dev.de/blog/?p=492) | 182 | - [Simple iPhone example using FreePascal and SDL](http://freeze-dev.de/blog/?p=492) |
| @@ -164,5 +187,7 @@ |
| 164 | | 187 | |
| 165 | ## External Links | 188 | ## External Links |
| 166 | | 189 | |
| 167 | - ["Developing with Objective Pascal" articles](http://dl.dropboxusercontent.com/u/28343282/ObjP/index.html) | 190 | - [Simon Choi's Basic Tutorial for Clean Installation for iOS 8.2](https://blog.naver.com/simonsayz/220305479793) |
| 168 | - <https://github.com/genericptr/Framework-Parser> - the primary Apple frameworks headers parser (used for FPC package) | 191 | - [Simon Choi's Basic Tutorial for Clean Installation for iOS 11.2.5](https://blog.naver.com/simonsayz/221209784815) |
| | 192 | - [The primary Apple frameworks headers parser (used for FPC package)](https://github.com/genericptr/Framework-Parser) |
| | 193 | - [Tips for Castle game engine project compilation for iOS](https://github.com/castle-engine/castle-engine/wiki/iOS) |