Swift 3: Getting data asynchronously before iPhone app launched - ios

In my app I have to get some data from webmethod before app launched, so I have to call a webmethod in this function:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {}
How can I block the function until the webmethod return its result?

Related

iOS Restore Auto Renewal Subscriptions

It's ok call restoreCompletedTransactions method once the user opens the app?
Or should Should I enqueue the method invocation in a background thread? Is it consider a blocking thread?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
registerForPushNotifications()
handleRemoteNotifications(launchOptions: launchOptions)
LoveSubscriptions.store.requestProducts(nil)
LoveSubscriptions.store.restorePurchases()
return true
}

Firebase Crashlytics integration not detecting or reporting crashes

I have integrated Crashlytics , here are the changes i have done.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Fabric.with([Crashlytics.self()])
Crashlytics.sharedInstance().debugMode = true
Have you added a key like.
"${PODS_ROOT}/Fabric/run" ed9c83ee83d41dc717a07531450c480895e41264 b6cc34ec354a4f96ab160958b4s2a01cc321be62acaa6116983376a5113c9s36

Why beforeInAppMessageDisplayed is never called?

I want to use Braze to send in-app message notification and show customized UI to replace the UI created by Braze. But beforeInAppMessageDisplayed is never called. Below is how I done.
I added
Appboy.start(withApiKey: apiKey, in: application, withLaunchOptions: launchOptions, withAppboyOptions: [ ABKInAppMessageControllerDelegateKey: self ]) in func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
and also added
func beforeInAppMessageDisplayed(inAppMessage: ABKInAppMessage!) -> ABKInAppMessageDisplayChoice
in AppDelegate class.
I resolved this issue by putting func beforeInAppMessageDisplayed(inAppMessage: ABKInAppMessage!) -> ABKInAppMessageDisplayChoice in ABKInAppMessageControllerDelegate.

Use of undeclared type 'UIApplicationLaunchOptionsKey'

Recently converted a project to Swift 2.2 and running into issues that didn't exist prior. I've tried searching for a workaround but haven't found any similar posts.
Use of undeclared type 'UIApplicationLaunchOptionsKey'.
I can't tell what's wrong with this code in the AppDelegate.swift:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
//UIToolbar.appearance().tintColor = UIColor.clearColor()
return true
}
Try changing the method signature to
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
return true
}
The signature is modified to func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool in swift 3
In Swift 3 the method is changed to:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}

Private func didFinishLaunchingWithOptions not being called? (Swift 3)

Isn't didFinishLaunchingWithOptions supposed to be called when the app starts running for the first time? I set a breakpoint at this method and when I run the app in the simulator the breakpoint doesn't get hit, which means the method doesn't get called. I'm trying to load some data from UserDefaults whenever the app launches, but it's being completely ignored. One thing I noticed is that it's by default a private func instead of a func. If I get rid of the private, I receive a warning that "there's an almost similar optional requirement in the UIApplicationDelegate". Can someone explain to me what this means and whether or not the private func has anything to do with the method being ignored? Is that method even supposed to be called when I run my app in the simulator? If not, how can I test if data is being retrieved after my app launches? All the other methods in the AppDelegate do get called normally (for example, the applicationDidEnterBackground method works perfectly fine).
Remove your method signature and have Xcode autocomplete it
I also had the problem that my didFinishLaunchingWithOptions method in AppDelegate would not be called. My function was also marked private and looked like this
private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
The problem is that this is the old syntax! Apparently for me when I converted my project from Swift 2.x to Swift 3 Xcode did not convert the methods in AppDelegate. The new syntax looks like this
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool
Swift 4.2:
func application( _ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool
for Swift ~3.0 Replace didFinishLaunchingWithOptions with
follwing signature
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
}
Have you implemented the didFinishLaunchingWithOptions in one of your ViewControllers? One will not get a call to the custom implementation of this method. This method is defined in the ApplicationDelegate and it will always be called once the app is launched. If you haven't defined the method again in any ViewController and the one in AppDelegate is not being called, then try resetting the simulator. From the simulator menu Simulator -> Reset content and settings.
If compiler prompts to make the didFinishLaunchingWithOptions method private then the parameter of the method might be causing the error.
The parameter of the application(_:didFinishLaunchingWithOptions:) delegate method is now bridged to Swift as a [UIApplicationLaunchOptionsKey: Any]?, rather than an [NSObject : AnyObject]?. So modify the method signature as shown.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// ...
}
This method is defined in the ApplicationDelegate and it will always be called once the app is launched. If you have not defined the method again in any ViewController and the one in AppDelegate is not being called, then try resetting the simulator.
Open simulator - > menu Simulator -> Reset content and settings.
-(BOOL)application(UIApplication*)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
//..
}
Update for Swift 4.2:
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool
Delete app from device and restart Xcode worked for me here

Resources