ios - Swift - 解析 Facebook "Invalid redeclaration of ' applicationDidBecomeActive'”

标签 ios facebook swift parse-platform

我正在尝试实现 Parse Facebook 登录功能,但我收到了一个“applicationDidBecomeActive”的无效重新声明。我不确定从哪里查明此错误的来源。

这是在我的 AppDelegate.swift 中触发错误的行:

**func applicationDidBecomeActive(application: UIApplication) {**
        FBAppCall.handleDidBecomeActiveWithSession(PFFacebookUtils.session())
    }

完整文件代码如下:

import UIKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

        Parse.setApplicationId("xxxxxx", clientKey:"xxxxxxx")
        PFFacebookUtils.initializeFacebook()

        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 throttle down OpenGL ES frame rates. 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:.
    }

    func application(application: UIApplication,
        openURL url: NSURL,
        sourceApplication: String?,
        annotation: AnyObject?) -> Bool {
            return FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication,
                withSession:PFFacebookUtils.session())
    }

    func applicationDidBecomeActive(application: UIApplication) {
        FBAppCall.handleDidBecomeActiveWithSession(PFFacebookUtils.session())
    }
}

这是我的桥接头文件:

//
//  Use this file to import your target's public headers that you would like to expose to Swift.
//

#import <FacebookSDK/FacebookSDK.h>
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import <Bolts/Bolts.h>

我似乎无法查明确切的错误,因为代码直接来自 Parse.com 文档。

最佳答案

如错误所述,您正在重新声明 applicationDidBecomeActive - 它在您的源代码中列出了两次。

从文件中删除以下行

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.
}

关于ios - Swift - 解析 Facebook "Invalid redeclaration of ' applicationDidBecomeActive'”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28823379/

相关文章:

iphone - iOS MapKit 最大缩放级别

iphone - 动画 GIF 图像作为 iphone 中的启动画面

javascript - 使用 api 在 facebook 页面上发布图像或状态

swift - 我们可以将 willSet 和 didSet 与 getter 和 setter 一起使用吗?

ios - 在 App Store Italy 上发布应用程序后,iAd 未在设备上显示

ios - 叠加场景/区域

android - loginButton.registerCallback 无法解析方法

java - com.android.ide.common.internal.LoggedErrorException 与 Facebook SDK

ios - 快速将 UIPanGestureRecognizer 限制为边界

objective-c - 如何混合 objective-c 和 swift 制作 cocoapods 框架