Steps I used just now to make a test iOS SDL app:
- Build iOS framework (make sure you select “Framework-iOS”, and next to it select “Build->Any iOS Device (arm64)”)
- Make a new Xcode project. For this one I chose the “Game” framework, since it doesn’t try to add as unneeded stuff (for macOS choose regular “App” template).
- Remove all added source code and other detritus. Leave
main.storyboard
,LaunchScreen.storyboard
, andAssets.xcassets
- Copy the iOS SDL2.framework to wherever YouriOSApp.xcodeproject is
- In build settings, under
General
, underFrameworks, Libraries, and Embedded Content
, add a new framework. ChooseAdd Other
and thenAdd Files
and then choose your iOS SDL2.framework -
This is the annoying part, and isn’t required for SDL3. On iOS, your app needs to run from a class that inherits from
UIAppDelegate
so it can handle all the various iOS things, like the app going to the background, low memory notifications, etc. Apparently, if you use the iOS static library it includes its ownmain()
function that creates and runs SDL’s own UIAppDelegate for you, which then calls yourmain()
. Since we aren’t using the static library, we have to create this ourself. So:
6.1) Create a file callediosmain.m
6.2) Fill it with the code below. It’s just doing the UIAppDelegate thing, which will then call yourmain()
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <SDL2/SDL_main.h>
#ifdef main
#undef main
#endif
int main(int argc, char *argv[])
{
return SDL_UIKitRunApp(argc, argv, SDL_main);
}
- Add your own main.c and source code.