How can I make this button open a new navigation controller programmatically? - ios

How can I make this button open a new navigation controller? I want it to force open a new controller from the right.
I need to do this all programmatically not using the storyboard.
#objc func buttonAction(sender: UIButton!) {
let loginDetailController = UIViewController()
navigationController?.pushViewController(loginDetailController, animated: true)
print("Button tapped")
}
Here is the code that makes the view controller I am editing pop up when a user is not logged in. This code is in the rootview controller.
func checkIfUserIsLoggedIn() {
if Auth.auth().currentUser?.uid == nil {
perform(#selector(handleLogout), with: nil,
afterDelay: 0)
}else{
let uid = Auth.auth().currentUser?.uid
Database.database().reference().child("users").child(uid!).observeSingleEvent(of: .value, with: {(snapshot) in
if let dictionary = snapshot.value as? [String: AnyObject] {
self.navigationItem.title = dictionary["name"] as? String
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
self.navigationController?.navigationBar.prefersLargeTitles = true
self.navigationController?.navigationBar.largeTitleTextAttributes = [NSAttributedStringKey.foregroundColor: UIColor.white]
}
},withCancel: nil)
}
}
override func didMove(toParentViewController parent: UIViewController?) {
checkIfUserIsLoggedIn()
}
#objc func handleLogout() {
do {
try Auth.auth().signOut()
} catch let logoutError {
print(logoutError)
}
let loginController = TwoLoginController()
present(loginController, animated: true, completion:
nil)
}
}
Here is where I added the dismiss of navigation controller.
func handleLogin() {
guard let email = emailTextField.text, let password = passwordTextField.text else{
print("invalid form")
return
}
Auth.auth().signIn(withEmail: email, password: password) { (user, error) in
if error != nil {
print(error!)
return
}
//logged in
self.dismiss(animated: true, completion: nil)
self.navigationController?.dismiss(animated: true, completion: nil)
}
}
New Approach?
import UIKit
import Firebase
class TwoLoginController: UINavigationController {

With Storyboards
First create a new file that is a custom viewController class. For this example we will call it YourCustomViewController. Then ( go to your storyboard and add a new viewController to the storyboard. Select that ViewController and give it an ID and set its class. After that is done put the following code in your function :
let controller = self.storyboard!.instantiateViewController(withIdentifier: "Your View's Identifier") as! YourCustomViewController
self.navigationController!.pushViewController(controller, animated: true)
Without Storyboards :
In your AppDelegate
// put the following code in your appDelegate didFinishLaunchingWithOptions function
window?.rootViewController = UINavigationController(rootViewController: HomeController(collectionViewLayout: layout))
UINavigationBar.appearance().barTintColor = UIColor.rgb(230, green: 32, blue: 31)
// get rid of black bar underneath navbar
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
application.statusBarStyle = .lightContent
let statusBarBackgroundView = UIView()
statusBarBackgroundView.backgroundColor = UIColor.rgb(194, green: 31, blue: 31)
window?.addSubview(statusBarBackgroundView)
window?.addConstraintsWithFormat("H:|[v0]|", views: statusBarBackgroundView)
window?.addConstraintsWithFormat("V:|[v0(20)]", views: statusBarBackgroundView)
In your Action to present the view
// this code belongs in your button's action
let dummyViewController = UIViewController()
dummyViewController.view.backgroundColor = .white
dummyViewController.navigationItem.title = "TEST"
navigationController?.navigationBar.tintColor = .white
navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
navigationController?.pushViewController(dummyViewController, animated: true)

After a discussion and getting more of the picture. This is how you should programmatically present a ViewController inside of a new NavigationController
#objc func handleLogout() {
do {
try Auth.auth().signOut()
} catch let logoutError {
print(logoutError)
}
let loginController = TwoLoginController()
let navVC = UINavigationController(rootViewController: loginController)
present(navVC, animated: true, completion: nil)
}
Then to destroy the navigation controller at the end it should be something like this:
self.navigationController?.dismiss(animated: true) {
//
}
Do this when the log in is completed when you need to segue to the next view.

Related

Pushnavigation is not working with custom alert in swift

I am using my custom alert to log out of the application
in custom alert, I have tried to log out with firebase after the successful logout using navigation push controller to sign in the controller but it will not redirect to sign in screen
Here is my custom alert code
let customAlert = self.storyboard?.instantiateViewController(withIdentifier: "CustomAlertID") as! AlertViewController
customAlert.titleLbl = "Log out"
customAlert.imageTitle = "logout"
customAlert.descryptionText = "You will be returned to the login screen. Are you sure you want to logout?"
customAlert.okBtnText = "LOG OUT"
DispatchQueue.main.async {
customAlert.providesPresentationContextTransitionStyle = true
customAlert.definesPresentationContext = true
customAlert.modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
customAlert.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
self.present(customAlert, animated: true, completion: nil)
}
Here is my logout click button code
let firebaseAuth = Auth.auth()
do {
try firebaseAuth.signOut()
let controller = self.storyboard?.instantiateViewController(withIdentifier: "SignInViewController") as! SignInViewController
self.navigationController?.pushViewController(controller, animated: true)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
self.navigationController?.popToRootViewController(animated: true)
}
let domain = Bundle.main.bundleIdentifier!
UserDefaults.standard.removePersistentDomain(forName: domain)
UserDefaults.standard.synchronize()
print(Array(UserDefaults.standard.dictionaryRepresentation().keys).count)
} catch let signOutError as NSError {
self.dismiss(animated: true, completion: nil)
print("Error signing out: %#", signOutError)
}
}
without the alert view, it will works
In order for the navigationController property to not be equal to nil, you must add your custom alertViewController to the navigation stack using pushViewController method. In your case, you are only presenting a custom alertViewController that does not know anything about your navigationController
There is another way to implement:
After initializing a custom view controller, you should pass it the necessary closure functions that should work after pressing the button
Example:
let customAlert = self.storyboard?.instantiateViewController(withIdentifier: "CustomAlertID") as! AlertViewController
customAlert.titleLbl = "Log out"
customAlert.imageTitle = "logout"
customAlert.onClickExit = { [weak self] in
self?.navigationController?.popViewController(animated: true)
}
...
After Logout, you should set Another Root view controller and Your navigationController Stack Must be Clear.
let controller = self.storyboard?.instantiateViewController(withIdentifier: "SignInViewController") as! SignInViewController
let signInNavController = UINavigaionController(rootViewController: controller)
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = signInNavController

Back button does not work in Navigation Controller

I try to implement a back button for my controllers.
My Navigation Controller implementation inside of the Container Controller:
func configureMainController(){
let mainController = MainController()
mainController.delegate = self
mainController.backDelegate = self
centerController = UINavigationController(rootViewController: mainController)
view.addSubview(centerController.view)
addChild(centerController)
centerController.didMove(toParent: self)
}
My Back Delegate:
extension ContainerController: BackDelegate {
func handleBack() {
print("ok")
centerController.navigationController?.popViewController(animated: true)
}
}
Back button inside of the Main Controller:
navigationItem.rightBarButtonItem = UIBarButtonItem(image: image2?.withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(backAction))
#objc func backAction() -> Void {
backDelegate?.handleBack()
}
How I push the Controller that I need to pop:
DispatchQueue.main.async {
let vc = ScienceController(collectionViewLayout: UICollectionViewFlowLayout())
vc.modalPresentationStyle = .fullScreen
self.navigationController?.pushViewController(vc, animated: true)
}
Here is my Main Controller with relevant functions:
class MainController: UIViewController {
let tabBarCnt = UITabBarController()
var delegate: MainControllerDelegate?
var backDelegate: BackDelegate?
override func viewDidLoad() {
super.viewDidLoad()
createTabBarController()
}
#objc func backAction() -> Void {
//self.navigationController?.popViewController(animated: true)
backDelegate?.handleBack()
}
func checkIfUserIsLoggedIn(){
if Auth.auth().currentUser?.uid == nil{
performSelector(inBackground: #selector(handleLogout), with: nil)
}
}
#objc func handleLogout(){
do {
try Auth.auth().signOut()
} catch let logoutError {
print(logoutError)
}
DispatchQueue.main.async {
// UIView usage
let loginController = LoginController()
loginController.mainController = self
loginController.modalPresentationStyle = .fullScreen
self.present(loginController, animated: true, completion: nil)
}
}
func createTabBarController() {
let firstVc = Controller1()
firstVc.title = "vc1"
firstVc.view.backgroundColor = UIColor.white
firstVc.tabBarItem = UITabBarItem.init(title: "vc1", image: nil, tag: 0)
let secondVc = Controller2()
secondVc.title = "vc2"
secondVc.view.backgroundColor = UIColor.white
secondVc.tabBarItem = UITabBarItem.init(title: "vc2", image: nil, tag: 1)
let thirdVc = Controller3()
thirdVc.title = "vc3"
thirdVc.view.backgroundColor = UIColor.white
thirdVc.tabBarItem = UITabBarItem.init(title: "vc3", image: nil, tag: 2)
let controllerArray = [firstVc, secondVc, thirdVc]
tabBarCnt.viewControllers = controllerArray.map{
UINavigationController.init(rootViewController: $0)}
//tabBarCnt.selectedIndex = 1
self.view.addSubview(tabBarCnt.view)
}
}
Here is my Container Controller:
class ContainerController: UIViewController {
// MARK: - Properties
var menuController: MenuController!
var centerController: UINavigationController!
var isExpanded = false
// MARK: - Init
override func viewDidLoad() {
super.viewDidLoad()
configureMainController()
}
override var preferredStatusBarStyle: UIStatusBarStyle {
return .darkContent
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation{
return .slide
}
override var prefersStatusBarHidden: Bool{
return isExpanded
}
// MARK: - Handlers
func configureMainController(){
let mainController = MainController()
mainController.delegate = self
mainController.backDelegate = self
centerController = UINavigationController(rootViewController: mainController)
view.addSubview(centerController.view)
addChild(centerController)
centerController.didMove(toParent: self)
}
func configureMenuController(){
if menuController == nil{
menuController = MenuController()
menuController.delegate = self
view.insertSubview(menuController.view, at: 0)
addChild(menuController)
menuController.didMove(toParent: parent.self)
}
}
func animatePanel(shouldExpand: Bool, menuOption: MenuOption?){
if shouldExpand{
//show
UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseInOut, animations: {
self.centerController.view.frame.origin.x = self.centerController.view.frame.width - 80
}, completion: nil)
}
else{
//hide
UIView.animate(withDuration: 0.5, delay: 0, options: .curveEaseInOut, animations: {
self.centerController.view.frame.origin.x = 0
}) { (_) in
guard let menuOption = menuOption else {return}
self.didSelectMenuOption(menuOption: menuOption)
}
}
animateStatusBar()
}
func didSelectMenuOption(menuOption: MenuOption){
switch menuOption {
case .Profile:
let controller = ProfileController()
present(UINavigationController(rootViewController: controller), animated: true, completion: nil)
case .Settings:
let controller = SettingsController()
//controller.username = "pasha"
present(UINavigationController(rootViewController: controller), animated: true, completion: nil)
case .Logout:
handleLogout()
}
}
func animateStatusBar(){
UIView.animate(withDuration: 0.5, delay: 0.0, options: .curveEaseInOut, animations: {
self.setNeedsStatusBarAppearanceUpdate()
}, completion: nil)
}
#objc func handleLogout(){
do{
try Auth.auth().signOut()
DispatchQueue.main.async {
UIApplication.shared.keyWindow?.rootViewController = LoginController()
}
//UIApplication.shared.keyWindow?.rootViewController?.dismiss(animated: true, completion: nil)
} catch let logoutError {
print(logoutError)
}
}
}
extension ContainerController: MainControllerDelegate {
func handleMenuToggle(forMenuOption menuOption: MenuOption?) {
if !isExpanded {
configureMenuController()
}
isExpanded = !isExpanded
animatePanel(shouldExpand: isExpanded, menuOption: menuOption)
}
}
extension ContainerController: BackDelegate {
func handleBack() {
print("ok")
centerController.popViewController(animated: true)
}
}
The print("ok") statement works but not centerController.navigationController?.popViewController(animated: true). I also tried self.navigationController?.popViewController(animated: true) and It does not work too...
Since UINavigationController is subclass of UIViewController it has navigationController property on it. You should not be using navigationController property present on UINavigationController. So your code should be
centerController.popViewController(animated: true)
Edit:
As "Sylvan D Ash" mentioned you are pushing and popping from 2 different controllers.
self.navigationController?.pushViewController(vc, animated: true)
need to be replaced with
centerController.pushViewController(vc, animated: true)

Presenting ViewController whenever it receive a notify cause memory leaking

I have a ViewController called Home, in Home viewDidAppear have a function CheckStatus that I need to call every time it received a specific notify.
So currently in AppDelegate, I call this code to present Home anytime the notify is received, which cause memory leaking and crashes:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let controller = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! MainTabBarController
//Home is the first ViewController of the TabBar
self.window?.rootViewController = controller
What is the solution for this?
Updated ViewDidAppear and it's functions
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.tabBarController?.tabBar.isHidden = false
setupTabbar() //setup tab bar UI
self.locationService.getLocation()
self.checkRequestStatus()
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
func checkRequestStatus(){
API.checkRequestStatus{ [weak self] json, error in
if let error = error {
}else {
if let json = json {
let status = json[Const.STATUS_CODE].boolValue
if (!API.isSuccess(response: json)){
if (API.getErrorCode(response: json) == Const.INVALID_TOKEN){
let alert = UIAlertController(title: "Message".localized(), message: "You have logged in from another device. Please login again.", preferredStyle: UIAlertController.Style.alert)
alert.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler:
{(action:UIAlertAction!) in
let defaults = UserDefaults.standard
print ("got here")
defaults.set("", forKey: Const.Params.TOKEN)
if self?.presentingViewController != nil {
self?.dismiss(animated: false, completion: {
self?.navigationController!.popToRootViewController(animated: true)
})
}
else {
self?.navigationController!.popToRootViewController(animated: true)
}
}))
self!.present(alert, animated: true, completion: nil)
}
}
let defaults = UserDefaults.standard
if let currency : String = json[Const.CURRENCEY].rawString() {
defaults.set(currency, forKey: json[Const.CURRENCEY].rawString()!)
}
if let cancellation : Int = json[Const.CANCELLATION_FINE].intValue {
let str : String = String(cancellation)
defaults.set(str, forKey: Const.CANCELLATION_FINE)
}
if(status){
let requestDetail: RequestDetail = RequestDetail()
let jsonAry:[JSON] = json[Const.DATA].arrayValue
let defaults = UserDefaults.standard
if jsonAry.count > 0 {
let driverData = jsonAry[0]
if driverData.exists() {
defaults.set(driverData["request_id"].stringValue, forKey: Const.Params.REQUEST_ID)
defaults.set(driverData["provider_id"].stringValue, forKey: Const.Params.DRIVER_ID)
requestDetail.initDriver(rqObj: driverData)
}
let invoiceAry:[JSON] = json[Const.INVOICE].arrayValue
if invoiceAry.count > 0 {
let invoiceData = invoiceAry[0]
defaults.set(invoiceData.rawString(), forKey: Const.CURRENT_INVOICE_DATA)
requestDetail.initInvoice(rqObj: invoiceData)
}
self?.processStatus(json: json, tripStatus:requestDetail.tripStatus)
} else {
requestDetail.tripStatus = Const.NO_REQUEST
let defaults = UserDefaults.standard
defaults.set(Const.NO_REQUEST, forKey: Const.Params.REQUEST_ID)
}
}
}
}
}
}
You are force-unwrapping self:
self!.present(alert, animated: true, completion: nil) First see if your app still crashes when your replace the call with self?..

Attempt to present UINavigationController whose view is not in the window hierarchy! (Swift)

I am running into the issue of my viewcontrollers not showing up even though the function calling the viewcontrollers seem to be running. The error I receive in the console is:
Warning: Attempt to present on whose view is not in the window hierarchy!
I have tried the suggestions on the "Attempt to present UIViewController on UIViewController whose view is not in the window hierarchy" thread without any progress. I am running everything programmatically.
func handleNewPage(){
print("this code works")
let uid = Auth.auth().currentUser?.uid
ref = Database.database().reference()
let usersReference = ref.child("patient").child((uid)!)
if usersReference.child("Doctor Code") != nil {
func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)
}
presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}
}
The function is called and the print statements come out valid. Yet, the viewcontrollers will not appear.
You have to create presentNewPage() function outside of your if ???
if usersReference.child("Doctor Code") != nil {
func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)
}
presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}
change it like this
func presentNewPage(){
let firstPage = LandingPage()
let navCon = UINavigationController(rootViewController: firstPage)
present(navCon, animated: true, completion: nil)
}
func handleNewPage(){
print("this code works")
let uid = Auth.auth().currentUser?.uid
ref = Database.database().reference()
let usersReference = ref.child("patient").child((uid)!)
if usersReference.child("Doctor Code") != nil {
presentNewPage()
print("PRINT")
} else{
let newPage = PresentViewController() // doctor reg page
let navController = UINavigationController(rootViewController: newPage)
present(navController, animated: true, completion: nil)
}
}

How to instantiate a viewController that is not in storyboard

Im currently using a custom tabBarController to navigate to my apps. I'm using storyboard for some of the view controllers and others Im not. the problem is that the viewControllers that are not in story are not being re instantiate. When I navigate to the view the first time everything work fine. If I exit and then come back the same view does not refresh. the same data is re-added on top of the old data. this happen to the views I could not add using an identifier to. The one i did self.storyboard?.instantiateViewController(withIdentifier: "LoginViewController") as! LoginViewController work fine. How can I solve this. Thank you in advance.
this work fine: this view behave normally because it was instantiate
let dashboardController = self.storyboard?.instantiateViewController(withIdentifier: "DashboardViewController") as! DashboardViewController
let dashboardTabImg = UIImage.fontAwesomeIconWithName(.User, textColor: iconColor, size: iconSize )
let dashboardTabImgSelected = UIImage.fontAwesomeIconWithName(.User, textColor: iconColor, size: iconSize)
dashboardController.tabBarItem = UITabBarItem(title: "Login", image: dashboardTabImg, selectedImage: dashboardTabImgSelected )
// this does not work properly because it was not instantiate.
//receivePostRequest VC
let receivePostRequest = UINavigationController(rootViewController: ReceivePostRequestViewController())
let receivePostRequestImg = UIImage.fontAwesomeIconWithName(.Dollar, textColor: iconColor, size: iconSize )
let receivePostRequestImgSelected = UIImage.fontAwesomeIconWithName(.Dollar, textColor: iconColor, size: iconSize)
receivePostRequest.tabBarItem = UITabBarItem(title: "Request", image: receivePostRequestImg, selectedImage: receivePostRequestImgSelected )
//This is the viewController that is im having issues with
import UIKit
import Firebase
class ReceivePostRequestViewController: UIViewController {
let receiveRequestSwitch = UISwitch()
let receiveRequestLabel = UILabel()
override func viewWillAppear(_ animated: Bool) {
navigationItem.title = "Post Request"
receiveRequestSwitch.isOn = false
checkFirBaseForSwitchStatus()
}
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
pageSetup()
receiveRequestSwitch.addTarget(self, action: #selector(postRequestSwitchButtonPressed), for: .touchUpInside)
}
}
enum receivePostStatusEnums{
case pending
case accepted
case disabled
case declined
case contactCustomerSupport
case error
}
extension ReceivePostRequestViewController {
func pageSetup(){
receiveRequestLabel.text = "Receive Post Request"
receiveRequestLabel.isUserInteractionEnabled = true
receiveRequestLabel.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(receiveRequestLabel)
receiveRequestLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: 80).isActive = true
receiveRequestLabel.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 26).isActive = true
receiveRequestLabel.rightAnchor.constraint(equalTo: view.rightAnchor, constant: -26).isActive = true
receiveRequestLabel.heightAnchor.constraint(equalToConstant: 44).isActive = true
receiveRequestLabel.addSubview(receiveRequestSwitch)
receiveRequestSwitch.frame = CGRect(x: 0, y: 0, width: 40, height: 44)
receiveRequestSwitch.translatesAutoresizingMaskIntoConstraints = false
// receiveRequestSwitch.leftAnchor.constraint(equalTo: receiveRequestLabel.leftAnchor).isActive = true
receiveRequestSwitch.rightAnchor.constraint(equalTo: receiveRequestLabel.rightAnchor).isActive = true
receiveRequestSwitch.centerYAnchor.constraint(equalTo: receiveRequestLabel.centerYAnchor).isActive = true
}
func checkFirBaseForSwitchStatus(){
FIRDatabase().childRef(refUrl: "frontEnd/users/\((FIRAuth.auth()?.currentUser?.uid)!)/receivePostRequest/info").observe(.value, with: {snapshot in
if let dict = snapshot.value as? NSDictionary {
if let stat = dict["isAvailabileForRequest"] as? Bool {
if stat{
self.receiveRequestSwitch.isOn = true
}else{
self.receiveRequestSwitch.isOn = false
}
}
}else{
self.receiveRequestSwitch.isOn = false
}
})
}
func postRequestSwitchButtonPressed(){
if self.receiveRequestSwitch.isOn{
receiveRequestSwitch.isOn = false
let userId = FIRAuth.auth()?.currentUser?.uid
FIRDatabase.database().reference().child("frontEnd/users/\(userId!)/receivePostRequest/application").observeSingleEvent(of: .value, with: {snapshot in
if let dict = snapshot.value as? [String:AnyObject]{
if let status = dict["status"] as? String {
print(status)
switch status {
case "pending":
print("its pending")
self.simpleAlert(title: nil, message: "Your application is currently Being Reviewed, no action is required from you")
case "accepted":
print("its accepted")
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PostSelectViewController")
self.present(viewController, animated: true, completion: nil)
case "disabled":
print("its disabled")
self.simpleAlert(title: nil, message: "Your account is currently disabled if you have any questions please contact customer service")
case "declined":
self.simpleAlert(title: nil, message: "After reviewing your application we will not be able to continue your application we are very sorry. If you feel this was an error please contact our customer service")
case "contactCustomerSupport":
print("its contactCustomerSupport")
self.simpleAlert(title: nil, message: "Please contact customer")
case "error":
print("its error")
self.simpleAlert(title: nil, message: "We can not process your request please try again at a later time")
default:
print ("error")
self.simpleAlert(title: nil, message: "We can not process your request please try again at a later time")
}
}
return
}
//user need submit application here
print("user need to fill out application page")
let applicationNavController = UINavigationController(rootViewController:ReceivePostRequestApplicationViewController())
self.present(applicationNavController, animated: true, completion: nil)
})
}else{
//update info to turn switch off
FIRDatabase().childRef(refUrl: "frontEnd/users/\((FIRAuth.auth()?.currentUser?.uid)!)/receivePostRequest/info").updateChildValues(["isAvailabileForRequest":false], withCompletionBlock: { (error, fir) in
if error != nil {
print(error?.localizedDescription)
return
}
let ac = UIAlertController(title: nil, message: "You will no longer receive service request", preferredStyle: .alert)
let okAction = UIAlertAction(title: "Ok", style: .default, handler: { (okAction) in
self.dismiss(animated: true, completion: nil)
})
ac.addAction(okAction)
self.present(ac, animated: true, completion: nil
)
})
}
}
}

Resources