首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS - NSNotificationCenter延迟

iOS - NSNotificationCenter延迟
EN

Stack Overflow用户
提问于 2017-03-25 20:30:27
回答 1查看 440关注 0票数 0

基本上,我试图创建一个应用程序,允许用户通过谷歌或Facebook登录。我已经成功地创建了整个登录过程,但是在显示Facebook配置文件图像时,我有一个小问题。因此,当用户选择登录Facebook或Google (从firstViewController.swift)登录时,他们会被发送到一个新的视图控制器(secondViewController.swift),在那里他们可以看到当前的Facebook配置文件图片(只有在使用FB登录的情况下),并且他们还可以选择使用按钮登录。另外,当他们登录到FB或Google时,他们可以关闭应用程序,当他们再次打开应用程序时,他们会被带回到第二个视图控制器,因为他们没有注销。

然而,当我在杀死应用程序后重新打开它(如果我使用FB登录),所有这些都是正常工作的,我用来查看FB配置文件图片的UIView出现了大约2秒的空白,然后它会改变到实际的FB图片,就像它想要的那样,我不知道如何消除这个延迟!这就是我的代码的样子:

Appdelegate.swift

代码语言:javascript
复制
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

代码语言:javascript
复制
@IBAction func handleCustomFBLogin() {
    FBSDKLoginManager().logIn(withReadPermissions: ["email", "public_profile"], from: self) { (result, err) in
        if err != nil {
            print("FB login failed", err!)
            return
        }
        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

代码语言:javascript
复制
 @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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-27 06:43:51

我相信这是网络调用脸谱API的配置文件图片,这需要2秒。尝试将fbProfilePicture的背景设置为颜色,然后您应该能够看到视图不是隐藏的不可见性,而是正在加载的图像,需要2秒。一个办法就是把它藏起来?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43021626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档