This is the code for both Google-signin and Facebook-signin. Google-signin works perfectly fine but Facebook "SDKApplicationDelegate" won't seem to work. I have imported all my pod (import FacebookCore, Facebook Login, FacebookShare).
Why is SDKApplication not working?
import UIKit
import GoogleSignIn
import FacebookCore
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GIDSignIn.sharedInstance().clientID = "1043921468178-epj1ms4mnc4tbf2j3vb0kudggfmtnc8b.apps.googleusercontent.com"
GIDSignIn.sharedInstance().delegate = self
return SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
let googleDidHandle = GIDSignIn.sharedInstance().handle(url as URL?,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation])
let facebookDidHandle = SDKApplicationDelegate.shared.application(app, open: url, options: options)
return googleDidHandle || facebookDidHandle
}
I was facing same problem, the solution I found was to import FBSDKCoreKit and rename it to ApplicationDelegate, but what I've done is to downgrade version of FacebookCore and FacebookLogin to the previous one (I was using 0.5.0) Facebook SDK seems to have a lot of bugs on this new version, I advise you to do the same.
Related
I would like to merge 'My code + Need to be added' but I don't know how to merge them because I haven't learnt Swift language.
This is needed to apply login function to our app, need your help.
Thank you.
***My code***
import UIKit
import Flutter
import Firebase
import GoogleMaps
import NaverThirdPartyLogin
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GMSServices.provideAPIKey("AIzaSyCkoa46_54eKawKWJGc9OskhLQ8hvV6mx4")
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
)
}
***Need to be added***
import NaverThirdPartyLogin
override func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return NaverThirdPartyLoginConnection.getSharedInstance().application(app, open: url, options: options)
}
I would like to use simple_auth_flutter into my FLutter app to authenticate user against instagram. So I followed the documentation page and applied all changes. I try to add the mentioned lines into my AppDelegate.swift as below:
import UIKit
import Flutter
import SimpleAuth;
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any]?) -> Bool{
return SimpleAuth.CheckUrl(url);
}
}
When I try to execute flutter run I see the error:
no such module 'SimpleAuth' import SimpleAuth;
So what should I do to solve the import in the AppDelegate? My pubspec.yml uses:
simple_auth: ^2.0.7
simple_auth_flutter: ^2.0.7
I think i've found a solution that allows my app to build.
import UIKit
import Flutter
import simple_auth_flutter;
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any]?) -> Bool{
return SimpleAuthFlutterPlugin.check(url);
}
}
I'm trying to put Facebook posting functionality into an iOS app of mine. I'm following the Facebook tutorial, and it tells me to put this code into my AppDelegate, which I've just migrated from Objective-C:
import UIKit
import FBSDKCoreKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
There is no "ApplicationDelegate" in my code; what should I do?
I'm trying to add the Facebook SDK in my flutter project but i don't know the proper Swift code to put in the AppDelegate.swift. Following this guide I should paste this code:
// AppDelegate.swift
import UIKit
import FBSDKCoreKit
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)
return true
}
func application(
_ app: UIApplication,
open url: URL,
options: [UIApplication.OpenURLOptionsKey : Any] = [:]
) -> Bool {
ApplicationDelegate.shared.application(
app,
open: url,
sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplication.OpenURLOptionsKey.annotation]
)
}
}
But the Flutter project has a different default code than the native:
import UIKit
import Flutter
#UIApplicationMain
#objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
Does anybody knows the proper way to merge them together?
I'm using the new Facebook Swift SDK instead of the Objective C SDK.
Previously, the openURL in AppDelegate.swift had to be implemented. However, Facebook's Swift tutorial doesn't cover this part.
The following is logged:
Implementation of application:openURL:sourceApplication:annotation: not found. Please add the handler into your App Delegate. Class: Shoppie.AppDelegate
But my implementation doesn't work:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: nil)
if (url.scheme?.hasPrefix("fb"))! {
return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: nil)
} else {
return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String, annotation: nil)
}
return false
}
Due to:
Use of unresolved identifier 'FBSDKApplicationDelegate'
I installed the Swift SDK by adding the following to my Podfile:
pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'
And running pod install.
I can't find what the updated code should be.
Their documentation is a bit lacking, but they do provide a good sample app in their github repository. see https://github.com/facebook/facebook-sdk-swift/blob/master/Samples/Catalog/Sources/AppDelegate.swift
Here's the code (Swift 3) I'm using to intergate the SDK into my apps:
import FacebookCore
#UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
SDKApplicationDelegate.shared.application(application, didFinishLaunchingWithOptions: launchOptions)
return true
}
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if let _ = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String {
return SDKApplicationDelegate.shared.application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
return false
}
#available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
if let _ = Bundle.main.object(forInfoDictionaryKey: "FacebookAppID") as? String {
return SDKApplicationDelegate.shared.application(application, open: url, options: options)
}
return false
}
}
FYI - the facebook swift library is basically just a wrapper to their standard objective-c library.
I fixed the Use of unresolved identifier 'FBSDKApplicationDelegate' issue by adding the following to my Bridging-Header.h file:
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
Login works after making these changes.
It seems the Facebook Swift SDK is still in beta, and the tutorials are yet to be updated. (Github Issue)