2016-08-10 13 views
0

我想了解的@UIApplicationMain的AUTOMAGIC以及如何可視化的iOS應用程序的啓動在Java中的術語:這個Java是@UIApplicationMain在Swift中的工作原理的一個很好的近似值?

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

退房這樣的回答: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代碼看起來像發生了什麼看球。

+0

當我抽象地思考軟件和「發生了什麼事」時,我想用Java來思考。我可以看到你的參考,但它不會「點擊」,因爲我不熟悉其他語言。 –

+0

它只是爲你創建'public static void main(String [] args)',並將你的'AppDelegate'傳遞給'UIApplicationMain',它是啓動應用程序並在特定點調用委託的框架類。 –

相關問題