我试图了解@UIApplicationMain
的自动化以及如何根据Java可视化iOS应用的开始:
public class UIApplication extends UIResponder implements Runnable {
final UIApplicationDelegate appDel;
public UIApplication(UIApplicationDelegate appDel) {
this.appDel = appDel;
}
public static void main(String[] args) {
try {
UIApplication app = new UIApplication(new AppDelegate());
handThisReferenceToOperatingSystem(app);
iOSdoesSomethingLikeThis(new Thread(app).start());
} catch(Exception e) { e.printStackTrace(); }
}
public void run() {
// chill-out and wait for iOS to invoke methods in UIResponder class.
// The UIResponder methods invoke my custom methods in AppDelegate.
}
public static class AppDelegate implements UIApplicationDelegate {
public void application(Object UIApplication) { // app specific behaviour
}
public void applicationWillResignActive(Object UIApplication) { // app specific behaviour
}
public void applicationDidEnterBackground(Object UIApplication) { // app specific behaviour
}
public void applicationWillEnterForeground(Object UIApplication) { // app specific behaviour
}
public void applicationDidBecomeActive(Object UIApplication) { // app specific behaviour
}
public void applicationWillTerminate(Object UIApplication) { // app specific behaviour
}
// maybe more methods from the UIApplicationDelegate
}
public interface UIApplicationDelegate {
void application(Object UIApplication);
void applicationWillResignActive(Object UIApplication);
void applicationDidEnterBackground(Object UIApplication);
void applicationWillEnterForeground(Object UIApplication);
void applicationDidBecomeActive(Object UIApplication);
void applicationWillTerminate(Object UIApplication);
// maybe some more methods ....
}
}
public class UIResponder {
void fingerSwipe() { // default implementation
}
void verticalMotion() { // default implementation
}
// more methods iOS might invoke
}
所以基本上,将@UIApplicationMain
属性应用于 AppDelegate 类会使所有其他代码消失,对吗?
答案 0 :(得分:0)
查看此答案:https://stackoverflow.com/a/24516329/335974
要点是它生成在Objective-C项目中找到的main.m
文件:
int main(int argc, char *argv[]) {
@autoreleasepool {
NSString *appDelegateClassName = @"AppDelegate";
return UIApplicationMain(argc, argv, nil, appDelegateClassName);
}
}
所以你的Java代码看起来就像发生了什么。