Wyler
Wyler

Reputation: 77

Facebook SDK error in AppDelegate application function even with updated Facebook in Xcode 6.3

So I updated Xcode and got a bunch of errors which were easy fixes but then, after updating the FBSDK, I got an error in my AppDelegate which I just can't seem to fix:

/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]?)'

The actual function giving the error is as follows:

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

The function is necessary for the Facebook login to work. Any help is appreciated. The function being invoked is as follows:

@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;

Please if anyone can help!

Upvotes: 3

Views: 1232

Answers (2)

Russell
Russell

Reputation: 3089

I just encountered this issue as well after upgrading to XCode 6.3 with Swift 1.2.

The issue appears to be that the sourceApplication type was updated from NSString to String in the function:

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

So it should be:

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

Cheers!

Edit: As noted by Ruud Kalis, the annotation type was also updated from AnyObject to AnyObject?

Upvotes: 7

Ruud Kalis
Ruud Kalis

Reputation: 264

Note also the change from AnyObject to AnyObject?. If this is not changed the compiler will still complain.

Upvotes: 1

Related Questions