Facebook SDK Swift - Use of undeclared identifier
Asked Answered
R

4

12

I am getting Use of undeclared identifier for every Facebook Object I use

Following this tutorial: TUTORIAL: HOW TO SHARE IN FACEBOOK SDK 4.1.X FOR SWIFT

But I've got the following error:

enter image description here

I've added Facebook framework via cocoapods:

pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'

And it was installed successfully

enter image description here

I've added bridging header

#ifndef Bridging_Header_h
#define Bridging_Header_h

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

#endif /* Bridging_Header_h */

The bridging header is connected:

enter image description here

I've configured my .plist

<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleURLSchemes</key>
            <array>
                <string>fb*****</string>
            </array>
        </dict>
    </array>
    <key>FacebookAppID</key>
    <string>*****</string>
    <key>FacebookDisplayName</key>
    <string>*****</string>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>facebook.com</key>
            <dict>
                <key>NSIncludesSubdomains</key> <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
            </dict>
            <key>fbcdn.net</key>
            <dict>
                <key>NSIncludesSubdomains</key> <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key>  <false/>
            </dict>
            <key>akamaihd.net</key>
            <dict>
                <key>NSIncludesSubdomains</key> <true/>
                <key>NSThirdPartyExceptionRequiresForwardSecrecy</key> <false/>
            </dict>
        </dict>
    </dict>

Here is the code:

let content : FBSDKShareLinkContent = FBSDKShareLinkContent()
        content.contentURL = NSURL(string: "<INSERT STRING HERE>")
        content.contentTitle = "<INSERT STRING HERE>"
        content.contentDescription = "<INSERT STRING HERE>"
        content.imageURL = NSURL(string: "<INSERT STRING HERE>")

        let button : FBSDKShareButton = FBSDKShareButton()
        button.shareContent = content
        button.frame = CGRectMake((UIScreen.mainScreen().bounds.width - 100) * 0.5, 50, 100, 25)
        self.view.addSubview(button)
Rotator answered 25/10, 2015 at 9:20 Comment(14)
did you run pod install or try running it againAnatolio
@OmkarGuhilot I did. It worked fine. The frameworks are in my Pods projectRotator
So is it solved and did it resolve by running pod install again ?Anatolio
@OmkarGuhilot, No. Getting the framework with pod was not the problem. The problem is that the framework is not recognizedRotator
Confirm the following: 1. Linker Flag in Build Settings is set to -ObjC 2. import statements are present at the top of your swift files for the facebook resources you are trying to callInteractive
@Kashif, 1.I have -ObjC linked flag 2. No. What exactly should I import? .h files in Swift?Rotator
When I do it (for example import FBSDKAccessToken.h), it writes "No such module 'FBSDKAccessToken.h'".Rotator
are you in swift or objective-C? Could you provide an example of the code you are trying to write?Nonary
Can you please show me 2 objects your getting the Use of undeclared identifier, I need evaluate what header import your missingSolorzano
This has nothing to do with your .plistSolorzano
@thibautnoah, I've updated the question with my error and codeRotator
@FarhadNezhad , I've updated the questionRotator
@Rotator Sound like someone answer it :) Happy Coding.Solorzano
Thanks I found my answer from your Question. :)Gorga
T
13

If you use Pods and your project is on Swift you don't need to import headers from pods to Bridging_Header_h It's suficient to import needed SDK to you swift file like:

import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
Twopence answered 1/11, 2015 at 9:14 Comment(1)
This is true. Also, you can go head and even initiate a variable for the classes. Nice catch Lurie.Solorzano
S
5

First step is create Podfile, for example:

use_frameworks!
pod 'ChameleonFramework/Swift'
pod 'GBDeviceInfo'

Save file and install or update pods by command:

pod install / pod update

Next, you should add in general settings framework:

enter image description here

Syringa answered 30/10, 2015 at 12:36 Comment(1)
I've added the frameworks where you sugested, but it dodn't help :( i65.tinypic.com/20l1idk.pngRotator
M
0

For Swift users: Facebook Swift SDK 0.7.0 and 0.8.0 seem to be completely FUBAR, there is no way to get imports to work properly even on a completely new project.

Revert to 0.6.0 by specifying the following in your Podfile, and the tutorials and imports will work again:

pod 'FacebookCore', '~> 0.6.0'
pod 'FacebookLogin', '~> 0.6.0'
pod 'FacebookShare', '~> 0.6.0' 
Manakin answered 22/8, 2019 at 10:48 Comment(0)
S
0

I was stuck at it too until I found that it is a debug and release issue.

instead of using

#ifndef Bridging_Header_h
#define Bridging_Header_h

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

#endif /* Bridging_Header_h */

You should use

#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKShareKit/FBSDKShareKit.h>

#ifndef Bridging_Header_h
#define Bridging_Header_h

#endif /* Bridging_Header_h */ 
Salable answered 1/2, 2022 at 6:30 Comment(1)
Moving the imports out of the #ifndef block is why this works. The block then has no purpose, and could be deleted in the interest of compact, clear codeLightsome

© 2022 - 2024 — McMap. All rights reserved.