2017-06-18 111 views
-1

我是編程新手,正在嘗試製作應用程序。我現在的問題是,當我啓動模擬器時,應用程序不顯示,只有黑色和頂部的電池/時間行。我嘗試過重新設置模擬器,清理程序以及其他對話中的許多其他內容,但沒有任何成效。可能是什麼問題呢?模擬器變成黑色

我可以插入你需要的編碼線。

的ViewController:

import UIKit 
import GoogleSignIn 
import Firebase 


@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { 


func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) { 

} 

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { 

} 
var window: UIWindow? 







func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool { 
FIRApp.configure() 

self.window = UIWindow(frame:UIScreen.main.bounds) 
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
var ViewController: ViewController = mainStoryboard.instantiateViewController(withIdentifier: "ExampleController") as! ViewController 

self.window?.rootViewController = ViewController 

self.window?.makeKeyAndVisible() 


var configureError: NSError? 
GGLContext.sharedInstance().configureWithError(&configureError) 
assert(configureError == nil, "Error configuring Google services: \(configureError)") 

GIDSignIn.sharedInstance().clientID = "YOUR_CLIENT_ID" 
GIDSignIn.sharedInstance().delegate = self 




GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID 




// Initialize sign-in 
return true 





    func application(_ application: UIApplication, 
        open url: URL, sourceApplication: String?, annotation: Any) -> Bool { 
     return GIDSignIn.sharedInstance().handle(url, 
               sourceApplication: sourceApplication, 
               annotation: annotation) 

    } 
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, 
       withError error: Error!) { 
     if let error = error { 
      print("\(error.localizedDescription)") 
      // [START_EXCLUDE silent] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil) 
      // [END_EXCLUDE] 
     } else { 
      // Perform any operations on signed in user here. 
      let userId = user.userID     // For client-side use only! 
      let idToken = user.authentication.idToken // Safe to send to the server 
      let fullName = user.profile.name 
      let givenName = user.profile.givenName 
      let familyName = user.profile.familyName 
      let email = user.profile.email 
      // [START_EXCLUDE] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), 
       object: nil, 
       userInfo: ["statusText": "Signed in user:\n\(fullName)"]) 
      // [END_EXCLUDE] 
     } 

     func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, 
        withError error: Error!) { 
      // Perform any operations when the user disconnects from app here. 
      // [START_EXCLUDE] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), 
       object: nil, 
       userInfo: ["statusText": "User has disconnected."]) 
      // [END_EXCLUDE] 


    } 

} 

故事板:

import UIKit 
import GoogleSignIn 
import Firebase 


@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate { 


func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, withError error: Error!) { 

} 

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { 

} 
var window: UIWindow? 







func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject: AnyObject]?) -> Bool { 
FIRApp.configure() 
return true 
self.window = UIWindow(frame:UIScreen.main.bounds) 
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil) 
var ViewController: ViewController = mainStoryboard.instantiateViewController(withIdentifier: "ExampleController") as! ViewController 

self.window?.rootViewController = ViewController 

self.window?.makeKeyAndVisible() 

return true 
var configureError: NSError? 
GGLContext.sharedInstance().configureWithError(&configureError) 
assert(configureError == nil, "Error configuring Google services: \(configureError)") 

GIDSignIn.sharedInstance().clientID = "YOUR_CLIENT_ID" 
GIDSignIn.sharedInstance().delegate = self 

return true 





GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID 




// Initialize sign-in 

return true 





    func application(_ application: UIApplication, 
        open url: URL, sourceApplication: String?, annotation: Any) -> Bool { 
     return GIDSignIn.sharedInstance().handle(url, 
               sourceApplication: sourceApplication, 
               annotation: annotation) 

    } 
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, 
       withError error: Error!) { 
     if let error = error { 
      print("\(error.localizedDescription)") 
      // [START_EXCLUDE silent] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), object: nil, userInfo: nil) 
      // [END_EXCLUDE] 
     } else { 
      // Perform any operations on signed in user here. 
      let userId = user.userID     // For client-side use only! 
      let idToken = user.authentication.idToken // Safe to send to the server 
      let fullName = user.profile.name 
      let givenName = user.profile.givenName 
      let familyName = user.profile.familyName 
      let email = user.profile.email 
      // [START_EXCLUDE] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), 
       object: nil, 
       userInfo: ["statusText": "Signed in user:\n\(fullName)"]) 
      // [END_EXCLUDE] 
     } 

     func sign(_ signIn: GIDSignIn!, didDisconnectWith user: GIDGoogleUser!, 
        withError error: Error!) { 
      // Perform any operations when the user disconnects from app here. 
      // [START_EXCLUDE] 
      NotificationCenter.default.post(
       name: Notification.Name(rawValue: "ToggleAuthUINotification"), 
       object: nil, 
       userInfo: ["statusText": "User has disconnected."]) 
      // [END_EXCLUDE] 


    } 

} 

func applicationWillResignActive(_ application: UIApplication) { 
    // 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 invalidate graphics rendering callbacks. Games should use this method to pause the game. 
} 

func applicationDidEnterBackground(_ application: UIApplication) { 
    // 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) { 
    // Called as part of the transition from the background to the active 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

請張貼您的代碼,否則它只是瘋狂的猜測。 – Losiowaty

+0

你需要什麼代碼? –

+0

你的初始視圖控制器應該是一個好開始,加上你可能在'storyboard' /'xib'中完成的任何配置 – Losiowaty

回答

0

看來你的問題就出在你的AppDelegate。看起來你在application:didFinishLaunchingWithOptions:方法中有多個return語句 - 執行不會到達第一個之後的部分。所以你的視圖控制器實例化將無法到達。只需刪除除最後一個之外的所有return語句,並且所有內容都可以正常工作。

+0

我現在已經嘗試過,但沒有奏效。我更新了問題中的AppDelegate,有沒有我忘記的東西? –

+0

你爲什麼這樣做 - 'self.window = UIWindow(frame:UIScreen.main.bounds)'?窗口應該由系統爲你初始化。 – Losiowaty

+0

這是另一個對話說如果模擬器是黑色的可以幫助,但是沒有幫助我,所以也許我應該刪除它。但問題出現在我插入之前。 –