Attempting to Load the View of a View Controller While It Is Deallocating... Uisearchcontroller

Attempting to load the view of a view controller while it is deallocating is not allowed for UISearchViewController

If you are creating a variable in a function (viewDidLoad) it's lifetime is the same as that functions lifetime. In this case you are trying to set the table header view as a searchController that is being deallocated (it's lifetime is the same as viewDidLoads)

When you create the variable outside of viewDidLoad and instantiate it later, the variable has the same lifespan as the viewController/class

Why: Attempting to load .. while deallocating... :UISearchController:

I would recommend using Storyboard Unwind Segues instead: https://developer.apple.com/library/ios/technotes/tn2298/_index.html

This insightful post also has a wealth of very useful implementation detail:

What are Unwind segues for and how do you use them?

Attempting to load the view of a view controller while it is deallocating SFAuthenticationViewController

You need to keep a reference to the SFAuthenticationSession at the top-level.
This should correct the issue:

import SafariService

class ViewController: UIViewController{
var authSession: SFAuthenticationSession?

///All my stuff
@IBAction func connectToReddit(){
let authURL = URL(string: "https://www.reddit.com/api/v1/authorize?client_id=myID&response_type=code&state=myState&redirect_uri=myRedirectURI&duration=permanent&scope=myscopes")

let scheme = "redditwatch://"
authSession = SFAuthenticationSession(url: authURL!, callbackURLScheme: scheme, completionHandler: { (url, error) in
print(url?.absoluteString)
print(error?.localizedDescription)
})

authSession?.start()
}
}

Credit for this fix to this Medium post: https://medium.com/the-traveled-ios-developers-guide/ios-11-privacy-and-single-sign-on-6291687a2ccc
I could not find a reference to the scope issue in the official documentation.

Edit: The official documentation now states "Ensure that there is a strong reference to the SFAuthenticationSession instance when the session is in progress." This seems to indicate the need to move the session up in scope. This is due to the behavior that occurs when the SFAuthenticationSession initializer displays the consent dialog.

Edit2: SFAuthenticationSession was deprecated in iOS 12 and replaced with ASWebAuthenticationSession. However, ASWebAuthenticationSession has the same scope requirement. This blog has a good description of how to convert.

BAD_EXC_ACCESS for attempting to load view controller while deallocating

The completion block of performQuery "must be capable of running on any thread of the app" (as described in the docs). You call addOverlay which is a UI function, and so much be called on the main queue. You need to dispatch this method to the main queue.

Side note, unrelated to the question: for(var i = 0; i<records.count; i += 1) is much better written as for record in records. The C-style syntax is deprecated.



Related Topics



Leave a reply



Submit