Swift - 解析 Facebook“'applicationDidBecomeActive' 的无效重新声明”

Posted

技术标签:

【中文标题】Swift - 解析 Facebook“\'applicationDidBecomeActive\' 的无效重新声明”【英文标题】:Swift - Parse Facebook "Invalid redeclaration of 'applicationDidBecomeActive'"Swift - 解析 Facebook“'applicationDidBecomeActive' 的无效重新声明” 【发布时间】:2015-03-03 03:04:19 【问题描述】:

我正在尝试实现 Parse Facebook 登录功能,我收到了 Invalid redeclaration of '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 文档。

【问题讨论】:

【参考方案1】:

正如错误所述,您正在重新声明 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.

【讨论】:

以上是关于Swift - 解析 Facebook“'applicationDidBecomeActive' 的无效重新声明”的主要内容,如果未能解决你的问题,请参考以下文章

解析 Facebook logInInBackgroundWithReadPermissions (Swift)

解析 Facebook 登录 Swift 3.0

Swift - 立即解析 Facebook 登录默认为用户取消登录

在 Swift 中链接/合并 Facebook 用户和 PFUser(解析)

在 swift 中将 Facebook 电子邮件存储在解析用户表中

如何从 swift 3 facebook 图形请求中解析这个 JSON