1

I am trying to integrate UrbanAirship into my project but I am getting the following error:

2016-08-25 16:26:23.898 Fibre[7758:368753] [E] __52+[UAirship handleAppDidFinishLaunchingNotification:]_block_invoke [Line 320] Please ensure that [UAirship takeOff] is called synchronously before application:didFinishLaunchingWithOptions: returns

Any help resolving this would be much appreciated!

My application delegate is as as below:

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

        // Override point for customization after application launch.
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

        let configuration = ParseClientConfiguration { (configuration) -> Void in

            configuration.applicationId = "******"                
            configuration.clientKey = "*****" 
            configuration.server = "https://*****.herokuapp.com/parse"       

        }

        Parse.initializeWithConfiguration(configuration)

        let config: UAConfig = UAConfig.defaultConfig()
        UAirship.takeOff(config)

        return true
    }
pableiros
  • 14,932
  • 12
  • 99
  • 105
MattBlack
  • 3,616
  • 7
  • 32
  • 58

1 Answers1

1

I haven't used the Urban Airship SDK before myself but going off of the error message that you posted the key bit seems to be "is called Synchronously before application:didFinishLaunchingWithOptions: returns".

What I would guess is happening is that you're calling the takeOff method on UAirship but didFinishLaunchingMethod is returning before that method completes; More than likely because it's being handled in another thread).

Try forcing the takeOff method to be run on the main thread with "dispatch_async" and then passing in the main queue such as:

dispatch_async(dispatch_get_main_queue(), {
    UAirship.takeOff(config)
})

Try that out, hopefully that will fix the issue.

Nick Jones
  • 58
  • 6
  • Hi, thanks for the response but I am still getting the same error :( – MattBlack Aug 25 '16 at 15:52
  • Can you try moving your takeOff code above the FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) call and see if that fixes the issue – Nick Jones Aug 25 '16 at 16:00
  • Hi, Yea I tried that and even removing the parse & FB config still gives the same error. – MattBlack Aug 25 '16 at 16:05
  • Doh, can you change that to dispatch_sync(dispatch_get_main_queue(), { instead and give that a go, hopefully that will solve the problem. – Nick Jones Aug 25 '16 at 16:14
  • Normally the app delegate methods are called on the main queue. I am curious why your app delegate method is being called so late. To work around this issue, you could try initializing UA in the load method of your class: http://stackoverflow.com/questions/24898453/swift-objective-c-load-class-method – ralepinski Aug 26 '16 at 16:28