Recently I decided to create an application for iOS using the C language. Now I have the following code:
#include <CoreFoundation/CoreFoundation.h> #include <objc/runtime.h> #include <objc/message.h> extern void UIApplicationMain(int, ...); int main(int argc, char *argv[]) { Class autoreleasePoolClass = objc_getClass("NSAutoreleasePool"); id autoreleasePool = objc_msgSend(objc_msgSend(autoreleasePoolClass, sel_registerName("alloc")), sel_registerName("init")); UIApplicationMain(argc, argv, nil, CFSTR("AppDelegate")); objc_msgSend(autoreleasePool, sel_registerName("drain")); return EXIT_SUCCESS; } The following function is defined in another file:
__attribute__((constructor)) void initAppDel() { AppDelClass = objc_allocateClassPair((Class) objc_getClass("UIResponder"), "AppDelegate", 0); objc_registerClassPair(AppDelClass); } In the OS simulator, this code runs without problems. However, if I launch it on a real device, the application immediately crashes. I can only assume that the thing is that I launch it on the arm64 device and I am calling something wrong. Has anyone come across this before (I understand that few people are addicted to such unusual perversions)?