ios - 将 Facebook SDK 与 Xcode Swift 项目集成 - AppDelegate 错误?

标签 ios swift xcode sdk cocoapods

我正在尝试根据此处的指南集成 Facebook SDK: https://developers.facebook.com/docs/swift/getting-started

我已经完成了 CocoaPods 步骤,现在正处于标题为“连接您的应用程序代理”的阶段。但是我从 Xcode 中收到错误阻止编译: 使用未解析的标识符:SDKApplicationDelegate 未解析标识符的用户:SDKApplicationDelegate

这是我的 AppDelegate。我是否缺少导入声明或其他内容?

    //
//  AppDelegate.swift
//  TestFBSDK
//
//  Created by laurie hocking on 09/02/2019.
//  Copyright © 2019 laurie hocking. All rights reserved.
//

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        SDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
        return true
    }
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        return SDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)
    }
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }


}

最佳答案

我只能认为我一直尝试使用 Cocoapods 的方式不对。当我最终手动导入框架时,它工作正常,如下所示:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
        incrementAppRuns()
        return true
    }

    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
                incrementAppRuns()
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

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

关于ios - 将 Facebook SDK 与 Xcode Swift 项目集成 - AppDelegate 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54610072/

相关文章:

swift - 如何获得 SKSpriteNode 的 physicsBody 的轨迹?

swift - 如何检查一个对象是否是一个集合? ( swift )

objective-c - 在iPad上非英语键盘输入时出错

ios - iOS 的 APNS 通知声音

ios - Xcode 上的 Tesseract 运行错误

ios - 理解 UIBezierPath 曲线机制、controlPoint 和曲线点

ios - 如何使用 Storyboard 中制作的 UIBarButtonItem 设置操作

swift - 使用 takeSnapshot 的 WKWebView 间歇性空白/部分屏幕截图

ios - Xcodebuild 测试无限期挂起而没有错误

ios - 强制关闭应用程序后位置更新是否继续运行