Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook SDK Swift - Use of undeclared identifier

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)
like image 988
Luda Avatar asked Oct 25 '15 09:10

Luda


2 Answers

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
like image 143
Iurie Manea Avatar answered Oct 04 '22 00:10

Iurie Manea


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

like image 26
Paweł Sternik Avatar answered Oct 04 '22 01:10

Paweł Sternik