ORStudios
ORStudios

Reputation: 3233

Cannot find 'ApplicationDelegate' in scope

I am installing the Facebook Graph API and Im currently stuck on the following. It seems like I am unable to find the Application Delegate from the Scene Delegate.

If you are using iOS 13 or above please add the following method to your SceneDelegate

// Swift
//
// SceneDelegate.swift

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
    guard let url = URLContexts.first?.url else {
        return
    }

    ApplicationDelegate.shared.application(
        UIApplication.shared,
        open: url,
        sourceApplication: nil,
        annotation: [UIApplication.OpenURLOptionsKey.annotation]
    )
}

When I apply the above I get the following error.

Cannot find 'ApplicationDelegate' in scope

Upvotes: 9

Views: 11998

Answers (2)

Amine Zeroual
Amine Zeroual

Reputation: 1

Import FBSDKCoreKit:

At the beginning of your AppDelegate.swift file, import the FBSDKCoreKit framework:

Swift

import FBSDKCoreKit

Targeted Replacement in application(_:open:options:):

Within the application(_:open:options:) method, replace the line using ApplicationDelegate.shared.application with FBSDKApplicationDelegate.sharedInstance().application: Swift

func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(
        application, open: url, sourceApplication: options[.sourceApplication] as? String,
        annotation: options[.annotation]
    )
}

Upvotes: 0

Karan Mehra
Karan Mehra

Reputation: 397

import FBSDKCoreKit in your SceneDelegate And It Works Fine

Upvotes: 22

Related Questions