AppDelegate.swift 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // AppDelegate.swift
  3. // BingHaoBang
  4. //
  5. // Created by zhangjidong on 16/3/31.
  6. // Copyright © 2016年 Zjdboy. All rights reserved.
  7. //
  8. import UIKit
  9. @UIApplicationMain
  10. class AppDelegate: UIResponder, UIApplicationDelegate {
  11. var window: UIWindow?
  12. func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
  13. //创建窗口
  14. window = UIWindow(frame: SCREEN_BOUNDS)
  15. // 得到当前应用的版本号
  16. let infoDictionary = NSBundle.mainBundle().infoDictionary
  17. let currentAppVersion = infoDictionary!["CFBundleShortVersionString"] as! String
  18. // 取出之前保存的版本号
  19. let userDefaults = NSUserDefaults.standardUserDefaults()
  20. let appVersion = userDefaults.stringForKey("appVersion")
  21. //判断APP是否第一次启动,每版本是否第一次启动
  22. if appVersion == nil || appVersion != currentAppVersion
  23. {
  24. //引导图
  25. self.window?.rootViewController = GuideViewController()
  26. // 保存最新的版本号
  27. userDefaults.setValue(currentAppVersion, forKey: "appVersion")
  28. }else{
  29. //创建根视图
  30. self.window?.rootViewController = MainTabBarController()
  31. }
  32. //显示窗口
  33. window?.makeKeyAndVisible()
  34. //FPS
  35. let fpslabel = FPSLabel(frame: CGRectMake(50, 30, 55, 20))
  36. self.window?.addSubview(fpslabel)
  37. return true
  38. }
  39. func applicationWillResignActive(application: UIApplication) {
  40. // 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.
  41. // 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.
  42. }
  43. func applicationDidEnterBackground(application: UIApplication) {
  44. // 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.
  45. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
  46. }
  47. func applicationWillEnterForeground(application: UIApplication) {
  48. // 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.
  49. }
  50. func applicationDidBecomeActive(application: UIApplication) {
  51. // 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.
  52. }
  53. func applicationWillTerminate(application: UIApplication) {
  54. // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
  55. }
  56. }