sách gpt4 ai đã đi

iOS - NSNotificationCenter 延迟

In lại 作者:行者123 更新时间:2023-11-30 12:34:39 27 4
mua khóa gpt4 Nike

基本上,我正在尝试创建一个允许用户通过 Google 或 Facebook 登录的应用程序。我已经成功创建了整个登录过程,但是在显示 Facebook 个人资料图像时遇到了一个小问题。因此,当用户选择使用 Facebook 或 Google 登录(来自firstViewController.swift)时,他们会被发送到一个新的 View Controller (secondViewController.swift),在那里他们可以看到他们当前的 Facebook 个人资料图片(仅当使用 FB 登录时) )并且他们还可以选择使用按钮注销。此外,当他们使用 FB 或 Google 登录时,他们可以终止该应用程序,当他们再次打开该应用程序时,他们会返回到第二个 View Controller ,因为他们没有注销。

一切都按预期工作,但是当我杀死应用程序后重新打开应用程序时(如果我使用 FB 登录),我用来查看 FB 配置文件图片的 UIView 会显示空白约 2 秒,然后更改为实际的 FB 图片,因为它是预期的,我不知道如何摆脱这种延迟!这就是我的代码的样子:

Appdelegate.swift

func applicationDidBecomeActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp();

GIDSignIn.sharedInstance().signInSilently()
if (GIDSignIn.sharedInstance().hasAuthInKeychain() || (FBSDKAccessToken.current() != nil)){
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "homePageVC") as! secondViewController
let appDelegate:AppDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = vc

NotificationCenter.default.post(name: NSNotification.Name(rawValue: "setFBProfilePictureID"), object: nil)
}

}

firstViewController.swift

@IBAction func handleCustomFBLogin() {
FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self) { (result, err) in
nếu err != nil {
print("FB login failed", err!)
trở lại
}
self.performSegue(withIdentifier: "loggedIn", sender: self) //sends user to the second VC
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "setFBProfilePictureID"), object: nil) //post notification for the FB profile picture view in homePage VC
}
}

SecondViewController.swift

 @IBOutlet weak var fbProfilePicture: FBSDKProfilePictureView! //fb profile pic UIView


override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.

NotificationCenter.default.addObserver(self, selector: #selector(setFBProfilePicture(Notification:)), name: NSNotification.Name(rawValue: "setFBProfilePictureID"), object: nil)

}
func setFBProfilePicture(Notification: NSNotification) {
fbProfilePicture.isHidden = false
}

1 Câu trả lời

我相信这是对 facebook API 的个人资料图片的网络调用,需要 2 秒。尝试将 fbProfilePicture 的背景设置为某种颜色,然后您应该能够看到 View 并未立即 Conceal ,而是正在加载图像,这需要 2 秒。一个想法可能是缓存它?

关于iOS - NSNotificationCenter 延迟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43021626/

27 4 0
Bài viết được đề xuất: ios - 自动播放 URL 中的 mp3
Bài viết được đề xuất: swift - 参数化类型的方法可以省略类型参数
Bài viết được đề xuất: ios - 如何在键盘上方显示键盘?
Bài viết được đề xuất: swift - 无法分配值: Function call returns immutable value
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com