Use of undeclared type 'UIApplicationLaunchOptionsKey' - ios

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
}

Related

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.

Appdelegate print() not working

I want to open my iOS app from and URL but when I put NSURL into fund application print() doesn't working.
please refer here
import UIKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
var openUrl:NSURL? //This is used when to save state when App is not running before the url trigered
func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//print("Host: \(url.host!)")
//let url = url.standardized
//NotificationCenter.default.post(name: NSNotification.Name(rawValue: "HANDLEOPENURL"), object:url!)
print("bbb")
return true
}
}
There is no AppDelegate method with that signature, so its not getting called
func application(_ application: UIApplication, openURL url: NSURL, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
The correct method signature is:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool`
You are confusing it with this method
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
EDIT
To respond to links from the web to iOS, use
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: #escaping ([Any]?) -> Void) -> Bool {

Swift 3: Getting data asynchronously before iPhone app launched

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?

'AnyObject' is not identical to '[NSObject : AnyObject]'

I am finding this error in my AppDelegate.swift file and it appears in the AppDidFinishLaunchingWithOptions function. It is raising the error on a line of code that is from the Parse framework.
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
The error is appearing on the launchOptions parameter. I will post the whole function to show that it should be correct. Also when I comment out the line of code the error disappears, but I still really want to be able to use the function and track the analytics. Here is the whole function:
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: AnyObject!) -> Bool
{
// Override point for customization after app launches
Parse.setApplicationId("removed on purpose", clientKey: "removed on purpose")
PFAnalytics.trackAppOpenedWithLaunchOptions(launchOptions)
PFFacebookUtils.initializeFacebook()
return true
}
I can't seem to find anything that relates to this error. If anyone has some insight I would really appreciate it!
Since Xcode 6 beta 7, when you want to call application:didFinishLaunchingWithOptions:, you have to replace:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {
/* ... */
}
with the following code:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
/* ... */
}
The last parameter of this method is no more a NSDictionary but a Dictionary of type [NSObject: AnyObject]?. Therefore, you must update your code (including your trackAppOpenedWithLaunchOptions: parameter type).
The launchOptions parameter should be declared as NSDictionary! instead of AnyObject!:
func application(application: UIApplication!, didFinishLaunchingWithOptions launchOptions: NSDictionary!) -> Bool {
// ...
}

Resources