Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing ViewController UI inside "didInitiate" function after login #98

Open
andrenaught opened this issue Feb 16, 2019 · 2 comments
Open
Labels
offtopic Issue is not in scope for this issue tracker

Comments

@andrenaught
Copy link

Mac OS Version: Mojave - 10.14.3
XCode Version: 10.1
Tested on both: ios 12.1 (iphone 8) & ios 10.3.3 (iphone 5c)

I managed to get the authentication to work, everything works I can get data from the user using their access token.

My only issue is trying to update the UI values on the current view controller after successful authentication, my UI Label display_name becomes nil after the app returns from the authentication phase in Spotify app or SFSafariViewController. Is there any way to update the display_name within didInitiate?

The weird part is that it works perfectly on the simulation: DispatchQueue.main.async works, but not on real devices

// In my ViewController.swift
class ViewController: UIViewController, SPTSessionManagerDelegate {
    @IBOutlet weak var display_name: UILabel!

    //protocol stubs for 'SPTSessionManagerDelegate'
    func sessionManager(manager: SPTSessionManager, didInitiate session: SPTSession)
    {
        print("success", session)
       
        DispatchQueue.main.async {
            self.display_name.text = "data from api" // Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
        }
    }
...

// In my AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    
    lazy var rootViewController = ViewController()
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
        rootViewController.sessionManager.application(app, open: url, options: options)
        print("application func")
        return true
    }
...
@satishkoladiya
Copy link

Any solutions?

@kkarayannis
Copy link

You probably haven't connected the var to the label in the storyboard

@kkarayannis kkarayannis added the offtopic Issue is not in scope for this issue tracker label Jan 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
offtopic Issue is not in scope for this issue tracker
Projects
None yet
Development

No branches or pull requests

3 participants