2016-06-16 8 views
1

私はXcodeの計測器で私のアプリケーションをプロファイリングしています。レベルを上げると、今度はフレームレートが低下することがわかりました。フレームレートが低下した500msの期間を選択すると、その時間の275msがAppDelegateに費やされていることがわかります。私は特別なことはしていません - 基本的には定型的なコードです。他の誰かがこの問題にぶつかりましたか?SpriteKit AppDelegateのゲームに多くの時間を費やす

Running Time Self (ms) Symbol Name 

275.0ms 100.0% 258.0  main 

ここに私AppDelegateのコードは次のとおりです。

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 
     return true 
    } 

    func applicationWillResignActive(application: UIApplication) { 
     print("about to enter background") 
     // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 
     // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 
    } 

    func applicationDidEnterBackground(application: UIApplication) { 
     print("entered background") 
     // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
     // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 
    } 

    func applicationWillEnterForeground(application: UIApplication) { 
     print("will become active") 
     //NSNotificationCenter.defaultCenter().postNotificationName("PauseGame", object: self) 
     // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 
    } 

    func applicationDidBecomeActive(application: UIApplication) { 
     // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 
    } 

    func applicationWillTerminate(application: UIApplication) { 
     // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 
    } 


} 

答えて

0

それは普通のことです。アプリデリゲートは実質的にアプリのルートオブジェクトです。 UIApplicationオブジェクト自体と同様に、アプリケーションデリゲートはシングルトンオブジェクトであり、実行時に常に存在します。

アプリデリゲートには、いくつかの重要な役割を実行します。

  • それはあなたのアプリケーションの起動コードが含まれています。
  • これは、アプリの状態の主要な変更に対応します。具体的には、 は、アプリが からフォアグラウンドに移行するなど、一時的な中断と、アプリの実行状態の変更に応答します。
  • リモート通知(プッシュ通知とも呼ばれる)、 メモリ不足警告、ダウンロード完了通知など、 など、アプリ外からの通知に応答します。
  • ステートの保存と復元が発生するかどうかを決定し、必要に応じて保存と復元のプロセスを支援します( )。
  • これは、アプリ自体をターゲットとするイベントに応答し、アプリのビューまたはビューコントローラに固有の ではありません。

アプリケーションデリゲートの主な仕事の1つは、システムによって報告された状態遷移に応答することです。発生したすべての状態変更に対して、システムはアプリケーションデリゲートの適切なメソッドを呼び出します。各状態には、アプリがどのように動作すると予想されるべきかを管理する異なるルールがあり、アプリのデリゲートメソッドはそれに応じてアプリの動作を調整する必要があります。詳細については

このAppleの公式guide

+1

はあなたの詳細な回答をありがとう参照してください! – claassenApps

関連する問題