Facebook SDK Swift - 使用未声明的标识符 [英] Facebook SDK Swift - Use of undeclared identifier
问题描述
我正在获得对我使用的每个Facebook对象使用未声明的标识符
按照本教程:
我已经通过Cocapod添加了Facebook框架:
pod'FBSDKCoreKit'
pod'FBSDKShareKit'
它已成功安装
我添加了桥接头
#ifndef Bridging_Header_h
#define Bridging_Header_h
#import< FBSDKCoreKit / FBSDKCoreKit.h>
#import< FBSDKShareKit / FBSDKShareKit.h>
#endif / * Bridging_Header_h * /
桥接头已连接:
我配置了我的.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> <真/>
< key> NSThirdPartyExceptionRequiresForwardSecrecy< / key> <假/>
< / dict>
< key> fbcdn.net< / key>
< dict>
< key> NSIncludesSubdomains< / key> <真/>
< key> NSThirdPartyExceptionRequiresForwardSecrecy< / key> <假/>
< / dict>
< key> akamaihd.net< / key>
< dict>
< key> NSIncludesSubdomains< / key> <真/>
< key> NSThirdPartyExceptionRequiresForwardSecrecy< / key> <假/>
< / dict>
< / dict>
< / dict>
以下是代码:
let content:FBSDKShareLinkContent = FBSDKShareLinkContent()
content.contentURL = NSURL(string:< INSERT STRING HERE>)
content.contentTitle =&INSERT STRING此处>中
content.contentDescription =< INSERT STRING HERE>
content.imageURL = NSURL(string:< INSERT STRING HERE>)
let按钮:FBSDKShareButton = FBSDKShareButton()
button.shareContent = content
button.frame = CGRectMake((UIScreen.mainScreen()。bounds.width - 100)* 0.5,50,100,25)
self.view.addSubview(button)
如果您使用Pods并且您的项目位于Swift,则不需要将头文件从pod Bridging_Header_h
将所需的SDK导入到swift文件中,如下所示:
import FBSDKCoreKit
import FBSDKLoginKit
import FBSDKShareKit
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:
I've added Facebook framework via cocoapods:
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
And it was installed successfully
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:
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)
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
这篇关于Facebook SDK Swift - 使用未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!