Current section

Files

Jump to
mob_new priv templates mob.new ios AppDelegate.m.eex
Raw

priv/templates/mob.new/ios/AppDelegate.m.eex

// AppDelegate.m — Boots the Mob BEAM on a background thread and presents
// a SwiftUI root view via UIHostingController (created by MobUIFactory).
#import <UIKit/UIKit.h>
#import <pthread.h>
#include "mob_beam.h"
#import "MobApp-Swift.h" // generated by swiftc; exposes MobUIFactory
static void* beam_thread(void* arg) {
mob_start_beam((const char*)arg);
return NULL;
}
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication*)app
didFinishLaunchingWithOptions:(NSDictionary*)opts {
self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
UIViewController* vc = [MobUIFactory makeRootViewController];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
mob_init_ui();
extern const char* mob_app_module(void);
pthread_t t;
pthread_create(&t, NULL, beam_thread, (void*)mob_app_module());
pthread_detach(t);
return YES;
}
@end
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
}
}