OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

SwiftUI Facebook login popup wont close?

  • Thread starter Thread starter Kodr.F
  • Start date Start date
K

Kodr.F

Guest
i am trying to implement facebook login button into my project , all good but the dialog once return from Facebook still open and not closing . i think its something related to URL app delegate its not firing since i am using SwiftUI without scenedelegate .

The login func which is work perfectly :

Code:
fileprivate func facebookLogin(){
    
    let fbLoginManager = LoginManager()
        fbLoginManager.logIn(permissions: ["public_profile", "email"], from: Tools.topViewController()! )
        {  (result, error) in
            
            if ( result != nil && (result?.isCancelled)! )
            {
                print("[LOGIN][FACEBOOK] cancecled by User")
                return
            }
            
            if  result != nil && (result?.grantedPermissions != nil)
            {
                print("[LOGIN][FACEBOOK] grantedPermissions")
                
                if((AccessToken.current) != nil)
                {
                    GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in
                        
                        if (error == nil)
                        {
                            
                            print("[LOGIN][FACEBOOK SUCCESS] \(String(describing: result))")
                            
                            var fb_result = result as! [String : Any]
                            
                            let name = fb_result["name"] as! String
               
                        }else
                        {
                            print("[LOGIN][FACEBOOK ERROR] \(String(describing: error))")
                        }
                        
                    })
                    
                }else
                //Something went Wrong !
                {
                    print("[LOGIN][FACEBOOK ERROR] Something went wrong! #1")
                }
                
            }
            //Something went Wrong !
            else{
                
            }
            
        }
}

App :

Code:
@main
struct LW_APP: App {

    @Environment(\.scenePhase) var scenePhase

   
    
    var body: some Scene {
        WindowGroup {
            
            w_landingTabs()
      
        }
        .onChange(of: scenePhase) { (newScenePhase) in
            switch newScenePhase {
            case .background:
                print("[APP] State : Background")
            case .inactive:
                print("[APP] State : Inactive")
            case .active:
                print("[APP] State : Active")
           
            @unknown default:
                print("[APP] State : Unknown")
            }
        }
    }
    
}

App delegate :

Code:
import UIKit
import FBSDKCoreKit

let APP_DELEGATE:APP_delegate = UIApplication.shared.delegate as! APP_delegate

class APP_delegate: UIResponder, UIApplicationDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
        
        ApplicationDelegate.shared.application(
                  application,
                  didFinishLaunchingWithOptions: launchOptions
              )
        
        print("[APP DELEGATE] MyAppDelegate didFinishLaunchingWithOptions called")
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        print("[APP DELEGATE] options: [UIApplication.OpenURLOptionsKey : Any] ")
            return ApplicationDelegate.shared.application(app, open: url, options: options)
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        print("[APP DELEGATE] applicationDidBecomeActive")
        AppEvents.activateApp()
    }
  
}

The screen i stuck on when return after login :

enter image description here
<p>i am trying to implement facebook login button into my project , all good but the dialog once return from Facebook still open and not closing . i think its something related to URL app delegate its not firing since i am using SwiftUI without scenedelegate .</p>
<p><strong>The login func which is work perfectly :</strong></p>
<pre><code>fileprivate func facebookLogin(){

let fbLoginManager = LoginManager()
fbLoginManager.logIn(permissions: ["public_profile", "email"], from: Tools.topViewController()! )
{ (result, error) in

if ( result != nil && (result?.isCancelled)! )
{
print("[LOGIN][FACEBOOK] cancecled by User")
return
}

if result != nil && (result?.grantedPermissions != nil)
{
print("[LOGIN][FACEBOOK] grantedPermissions")

if((AccessToken.current) != nil)
{
GraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, email"]).start(completionHandler: { (connection, result, error) -> Void in

if (error == nil)
{

print("[LOGIN][FACEBOOK SUCCESS] \(String(describing: result))")

var fb_result = result as! [String : Any]

let name = fb_result["name"] as! String

}else
{
print("[LOGIN][FACEBOOK ERROR] \(String(describing: error))")
}

})

}else
//Something went Wrong !
{
print("[LOGIN][FACEBOOK ERROR] Something went wrong! #1")
}

}
//Something went Wrong !
else{

}

}
}
</code></pre>
<p><strong>App :</strong></p>
<pre><code>@main
struct LW_APP: App {

@Environment(\.scenePhase) var scenePhase



var body: some Scene {
WindowGroup {

w_landingTabs()

}
.onChange(of: scenePhase) { (newScenePhase) in
switch newScenePhase {
case .background:
print("[APP] State : Background")
case .inactive:
print("[APP] State : Inactive")
case .active:
print("[APP] State : Active")

@unknown default:
print("[APP] State : Unknown")
}
}
}

}
</code></pre>
<p>App delegate :</p>
<pre><code>import UIKit
import FBSDKCoreKit

let APP_DELEGATE:APP_delegate = UIApplication.shared.delegate as! APP_delegate

class APP_delegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {

ApplicationDelegate.shared.application(
application,
didFinishLaunchingWithOptions: launchOptions
)

print("[APP DELEGATE] MyAppDelegate didFinishLaunchingWithOptions called")
return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("[APP DELEGATE] options: [UIApplication.OpenURLOptionsKey : Any] ")
return ApplicationDelegate.shared.application(app, open: url, options: options)
}

func applicationDidBecomeActive(_ application: UIApplication) {
print("[APP DELEGATE] applicationDidBecomeActive")
AppEvents.activateApp()
}

}
</code></pre>
<p>The screen i stuck on when return after login :</p>
<p><a href="https://i.sstatic.net/LMumx.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LMumx.png" alt="enter image description here" /></a></p>
Continue reading...
 

Latest posts

Online statistics

Members online
0
Guests online
2
Total visitors
2
Ads by Eonads
Top