applicationDidBecomeActive

applicationDidBecomeActive

我正在尝试实现Parse Facebook登录函数,并收到一个Invalid redeclaration of 'applicationDidBecomeActive'。我不确定这个错误是从哪里来的。
这是触发myAppDelegate.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“'applicationDidBecomeActive'的无效重新声明”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28823379/

10-11 17:41