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
Uiview Backgroundcolor Disappears When Uitableviewcell Is Selected
Atos Cannot Get Symbols from Dsym of Archived Application
How to Remove an iOS App from the App Store
When Do App Sources Need to Be Included in Test Targets
What #Defines Are Set Up by Xcode When Compiling for Iphone
Storing Authentication Tokens on iOS - Nsuserdefaults VS Keychain
How to Set the Uinavigationbar with Gradient Color
Facebook Sdk: App Not Registered as a Url Scheme
Get the Current View Controller from the App Delegate
Linking Objective-C Categories in a Static Library
How to Hide Tab Bar with Animation in iOS
How to Set the Full Width of Separator in Uitableview
How to Dismiss Keyboard iOS Programmatically When Pressing Return
Simply Mask a Uiview with a Rectangle