AppDelegate应用程序功能中的Facebook SDK错误,即使在Xcode 6.3中更新了Facebook

时间:2015-04-11 17:43:22

标签: xcode swift appdelegate

所以我更新了Xcode并得到了一堆很容易修复的错误但是在更新了FBSDK之后,我的AppDelegate出现了一个错误,我似乎无法修复:

/Users/wylerzahm/Desktop/AppName/AppName/AppDelegate.swift:23:58: Cannot invoke 'application' with an argument list of type '(UIApplication, openURL: NSURL?, sourceApplication: NSString?, annotation: [NSObject : AnyObject]?)'

给出错误的实际功能如下:

func application(application: UIApplication, openURL url: NSURL?, sourceApplication: NSString?, annotation: [NSObject: AnyObject]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

此功能是Facebook登录工作所必需的。任何帮助表示赞赏。 被调用的函数如下:

@interface FBSDKApplicationDelegate : NSObject

+ (instancetype)sharedInstance;

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
     annotation:(id)annotation;


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;

请有人帮忙!

2 个答案:

答案 0 :(得分:7)

我在使用Swift 1.2升级到XCode 6.3之后也遇到了这个问题。

问题似乎是sourceApplication类型已在函数中从NSString更新为String

func application(application: UIApplication, openURL url: NSURL, sourceApplication: NSString?, annotation: AnyObject) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

所以它应该是:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

干杯!

编辑:正如Ruud Kalis所述,注释类型也从AnyObject更新为AnyObject?

答案 1 :(得分:1)

另请注意从AnyObjectAnyObject?的更改。如果没有改变,编译器仍然会抱怨。