How to use both google + and facebook inputs in one appdelegate.swift

My application uses google + signin and in my appdelegate.swift I have:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().delegate = self return true } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation) } 

Now I would like to insert also facebook login, but I need to add this code to appdelegate.swift:

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application( application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) } 

But this is the opposite error, because the โ€œfunctionsโ€ application already exists, how can I execute both google + and facebook, the same appdelegate.swift Thank you.

+10
ios iphone facebook swift2 google-plus
Feb 19 '16 at 16:45
source share
2 answers

Your application should process facebook and google links, and then return true if one or other can handle the given link.

 func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { let googleDidHandle = GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation) let facebookDidHandle = FBSDKApplicationDelegate.sharedInstance().application( application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) return googleDidHandle || facebookDidHandle } 

And in didFinishLaunching :

 func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { // Override point for customization after application launch. var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(configureError)") GIDSignIn.sharedInstance().delegate = self return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) } 
+52
Feb 19 '16 at 16:54
source share

In Swift 3, you need to do this:

Cancel and implement the following method:

  func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool { let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String let annotation = options[UIApplicationOpenURLOptionsKey.annotation] let googleHandler = GIDSignIn.sharedInstance().handle( url, sourceApplication: sourceApplication, annotation: annotation ) let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application ( app, open: url, sourceApplication: sourceApplication, annotation: annotation ) return googleHandler || facebookHandler } 

Then:

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { PFFacebookUtils.initializeFacebook(applicationLaunchOptions: launchOptions) FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) var configureError: NSError? GGLContext.sharedInstance().configureWithError(&configureError) assert(configureError == nil, "Error configuring Google services: \(String(describing: configureError))") return true } 
+10
Mar 04 '17 at 14:37
source share



All Articles