Packages
mob_new
0.4.13
0.4.20
0.4.19
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.45
0.1.44
0.1.43
0.1.42
0.1.40
0.1.33
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.25
0.1.24
0.1.23
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Project generator for the Mob mobile framework
Current section
Files
Jump to
Current section
Files
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
// Declared in mob_nif — delivers {:push_token, :ios, token} to the registered screen process.
extern void mob_send_push_token(const char* hex_token);
// Code-generated by MobDev.Plugin.IOSBootstrap at build time — registers each
// activated plugin's SwiftUI view with MobNativeViewRegistry.shared. Defined
// via Swift's @_cdecl in the generated file so it's a plain C symbol; safe to
// call before mob_init_ui() even when no plugins are activated (the function
// body is just empty in that case).
extern void mob_register_plugins(void);
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];
// Must run before mob_init_ui() so the registry has every plugin view
// factory in place by the time the BEAM mounts its first screen.
mob_register_plugins();
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;
}
- (void)application:(UIApplication*)app
didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken {
// Convert token bytes to hex string and deliver to Elixir via NIF.
NSMutableString* hex = [NSMutableString stringWithCapacity:deviceToken.length * 2];
const unsigned char* bytes = (const unsigned char*)deviceToken.bytes;
for (NSUInteger i = 0; i < deviceToken.length; i++) {
[hex appendFormat:@"%02x", bytes[i]];
}
mob_send_push_token([hex UTF8String]);
}
- (void)application:(UIApplication*)app
didFailToRegisterForRemoteNotificationsWithError:(NSError*)error {
NSLog(@"[Mob] Failed to register for remote notifications: %@", error);
}
@end
int main(int argc, char* argv[]) {
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, @"AppDelegate");
}
}