iosswift

How can my "didFinishLaunchingWithOptions" wait until call API finish


How can my application wait until my call API is finished?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    
    GMSServices.provideAPIKey("AIzadGlsfR35k4BeHCXmRq3GDSQ-l_5gcD8")
    FlicAuth.sharedInstance
  
    //Call Api here
    
    application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil))
    application.registerForRemoteNotifications()
    
    if(launchOptions?[UIApplicationLaunchOptionsLocationKey] != nil){
        LocationService.sharedInstance.startMonitoringLocation()
    }
    
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

Solution

  • It's very wrong, but for your problem i've a better solution.

    Create a viewController exactly same as your splash screen and set as initial viewController.. perform your operation in that viewController's class and after Api success you can navigate to your actual screen or change the root programmatically