简体   繁体   中英

Splash Screen Issue iPhone

I am using Launch screen in Xcode to do splash screen for my app.

There is only an image on splash screen, no API hit in background.
It is taking too long on the splash screen by which the time exceed of 20 Sec and app crashed there, I have checked it on device log as well.

Sometime it crashes and sometimes it runs but it always takes too long.
I am not able to move to next screen from there. And it shows a white screen before the splash screen for only iPhone 6 Plus (no white screen on other devices).

How to come out the white screen issue for iPhone 6 Plus and resolve the splash screen time long issue ?

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

        // Override point for customization after application launch.
        // self.prepareForContact()
        if let a: AnyObject = (NSUserDefaults.standardUserDefaults().objectForKey("isFirstTime"))
        {
            if let a: AnyObject = (NSUserDefaults.standardUserDefaults().objectForKey("userid"))
            {
                self.createAppFromHomepage()
            }
        }
        else
        {
            self.createAppFromWelcomeScreen()
        }

        isAllImageDownloading = false
        // Save this data to hit friend service on login on every launch...
        NSUserDefaults.standardUserDefaults().setObject("1", forKey: "hitFriendService")

        let credentialsProvider = AWSCognitoCredentialsProvider(regionType: CognitoRegionType, identityPoolId: CognitoIdentityPoolID)
        let configuration = AWSServiceConfiguration(region: DefaultServiceRegionType, credentialsProvider: credentialsProvider)
        AWSServiceManager.defaultServiceManager().defaultServiceConfiguration = configuration

        //print(credentialsProvider.secretKey)

        if let event_id: AnyObject = NSUserDefaults.standardUserDefaults().objectForKey("eventId")
        {
            self.getEventDescription()
            self.uploadEventRemainingImages()
        }


        let session1 = AVAudioSession.sharedInstance()
        session1.setCategory(AVAudioSessionCategoryPlayAndRecord, withOptions: AVAudioSessionCategoryOptions.MixWithOthers|AVAudioSessionCategoryOptions.DefaultToSpeaker|AVAudioSessionCategoryOptions.AllowBluetooth, error: nil)
        session1.setActive(true, error: nil)
        UIApplication.sharedApplication().beginReceivingRemoteControlEvents()


        let nsDocumentDirectory = NSSearchPathDirectory.DocumentDirectory
        let nsUserDomainMask    = NSSearchPathDomainMask.UserDomainMask
        if let paths = NSSearchPathForDirectoriesInDomains(nsDocumentDirectory, nsUserDomainMask, true)
        {
        if let dirPath = paths[0] as? String
        {
            self.excludeFromBackupToICloud(dirPath)
        }
        }

        if application.respondsToSelector("registerUserNotificationSettings:") {

            let types:UIUserNotificationType = (.Alert | .Badge | .Sound)
            let settings:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: nil)

            application.registerUserNotificationSettings(settings)
            application.registerForRemoteNotifications()
        }
        else
        {
            // Register for Push Notifications before iOS 8
           // application.registerForRemoteNotificationTypes(.Alert | .Badge | .Sound)
        }

         if let isFirstTime: AnyObject = NSUserDefaults.standardUserDefaults().objectForKey("isFirstTime")
         {
         }
        else
         {
            UIApplication.sharedApplication().applicationIconBadgeNumber = 0
          //  NSUserDefaults.standardUserDefaults().setObject("1", forKey: "isFirstTime")
         }
        return true
    }

You are being killed by the watchdog. Your app does not crash per say.

Investigate

Profile your app under Instruments : You will see right away what is taking so long.

Fix

Allow didFinishLaunchingWithOptions to return immediately. Factor out all the hard work in a separate method, which you can invoke like so:

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.performSelectorOnMainThread("didFinishLaunching", withObject: nil, waitUntilDone: false)
    return true
}

and do the hard work after returning (next event loop)

func didFinishLaunching() {
    // time consuming work goes here
}

Objective-C

[self performSelectorOnMainThread:@selector(didFinishLaunching)
                       withObject:nil
                    waitUntilDone:NO];

- (void) didFinishLaunching {
    // time consuming work goes here
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM