I am a beginner in iOS development. I have a problem when I move the screen. I clicked the button on the story board, then drag it with the right mouse, and then clicked on the view controller that I wanted to move. However, the navigation back button is not visible when the button is pressed. What's the reason?
Main.storyboard
Cell phone
Move when the lower right yellow button is pressed.
Move when the lower right yellow button is pressed. My right button is not 'Bar Button Item' but just a button. The reason is that 'Bar Button' is not what I want.
************************ Edited Start ************************************
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "goAgreeScreen" {
performSegue(withIdentifier: "goAgreeScreen", sender: self) // get Error
} else if segue.identifier == "otherScreen" {
}
}
Error is Thread 1: EXC_BAD_ACCESS (code=2, address=0x7ffee5677ff8)
************************ Edited end ************************************
*******************Edited Two *******************************************
Move Main Screen Button
#IBAction func Onclick(_ sender: Any) {
AVCaptureDevice.requestAccess(for: AVMediaType.video) { response in
if response {
print(response , ": granted")
let center = UNUserNotificationCenter.current()
// Request permission to display alerts and play sounds.
center.requestAuthorization(options: [.alert, .sound])
{ (granted, error) in
if granted {
print(granted, ": is granted")
DispatchQueue.main.async { self.moveScreen()}
} else {
print(granted, ": is not granted")
DispatchQueue.main.async { self.moveScreen()}
}
}
} else {
print(response , ": not granted")
let center = UNUserNotificationCenter.current()
// Request permission to display alerts and play sounds.
center.requestAuthorization(options: [.alert, .sound])
{ (granted, error) in
if error == nil {
if granted == true {
print(granted, ": is granted")
DispatchQueue.main.async { self.moveScreen()}
}
else {
print(granted, ": is not granted")
DispatchQueue.main.async { self.moveScreen()}
}
} else {
print(error as Any)
}
}
}
}
}
*******************Edited Two end *****************************************
Are you presenting the ViewController programmatically? It seems that the navigation bar is not shown.
Maybe you have to present if in a IBAction. Create it connecting a button. Set the identifier to the segue (on the Storyboard) and call it with:
performSegue(withIdentifier: "myIdentifier", sender: self)
I think that you don't need any code for your situation. Here is a Quick-Start example from Apple which is very clear.
https://developer.apple.com/library/archive/referencelibrary/GettingStarted/DevelopiOSAppsSwift/ImplementNavigation.html#//apple_ref/doc/uid/TP40015214-CH16-SW1
Related
I am trying to jump to a second view controller after I have authorized a user's TouchID. I am able to validate that the TouchID is working but I am having an issue of jumping to a second viewController.
I have created a SecondViewController and a Segue with the Identifier "dispenseScreen". However, whenever I try to jump to the second screen my program crashes.
#IBAction func touchID(_ sender: Any)
{
let context:LAContext = LAContext()
//Removes Enter Password during failed TouchID
context.localizedFallbackTitle = ""
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil)
{
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "We require your TouchID", reply: { (wasCorrect, error) in
self.isBiometryReady()
if wasCorrect {
self.performSegue(withIdentifier: "dispenseScreen", sender: self)
print("Correct")
}
else {
print("Incorrect")
}
})
} else {
//Enter phone password if too many login attempts
//Add message alerting user that TouchID is not enabled
}
}
There are no semantic errors in my code but I am receiving a threading error when I try to go to the second view controller.
You're trying to do the segue in the callback from evaluatePolicy. For anything involving UI, you need to make sure you're on the main thread: (wasCorrect, error) in DispatchQueue.main.async { ... }
when click button I added face id recognition and if true, need to navigate another page. But not working. application crashed. After few minutes navigate to the next page and back button not working.
#IBAction func myProfile(_ sender: Any) {
// self.performSegue(withIdentifier: "MyProfile", sender: nil)
let context:LAContext = LAContext()
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: nil){
context.evaluatePolicy(LAPolicy.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Need to access with your finger print", reply: {(wasCorrect, error) in
if wasCorrect{
print("correct")
self.performSegue(withIdentifier: "MyProfile", sender: nil)
}else{
print("incorrect")
}
})
}else{
print("finger print doesn't support touch id")
}
}
Error message is:
[Animation] +[UIView setAnimationsEnabled:] being called from a
background thread. Performing any operation from a background thread
on UIView or a subclass is not supported and may result in unexpected
and insidious behavior.
Callback of evaluatePolicy runs in a background queue so do
DisptachQueue.main.async {
self.performSegue(withIdentifier: "MyProfile", sender: nil)
}
I'm trying to detect when the facebook login viewcontroller gets dismissed so I can stop the loading animation. I implemented the facebook login SDK through firebase, and I'm logging in using this method:
#IBAction func facebookSignIn(_ sender: UIButton) {
loginBtn.startLoadingAnimation()
FBSDKLoginManager().logIn(withReadPermissions: ["email"], from: self) { (result, err) in
if err != nil {
print("CustomFB Login Failed: ", err)
self.loginBtn.stopLoadingAnimation()
return
}
}
}
How would I detect when the login viewcontroller gets dismissed?
This is simple, you have put stopLoadingAnimation() in the wrong place.
#IBAction func facebookSignIn(_ sender: UIButton) {
loginBtn.startLoadingAnimation()
FBSDKLoginManager().logIn(withReadPermissions: ["email"], from: self) { (result, err) in
self.loginBtn.stopLoadingAnimation()
//Facebook login is complet after Two case, failer and success.
if err != nil {
print("CustomFB Login Failed: ", err)
return
}
}
}
Stop spinner login is under if condition, but user clicks on cancel then your spinner does not stop.
#IBAction func addInformation(_ sender: UIBarButtonItem) {
// check rateHourly has value
if let editedRateHourly = rateHourly.text {
print("editedRateHourly condition is \(editedRateHourly)")
if editedRateHourly != ""{
print("not nil")
// check edit value is number?
let num = Int(editedRateHourly)
if num != nil {
print("is num")
// add to database
UserDefaults.standard.set(editedRateHourly, forKey: "\(findDate())")
UserDefaults.standard.synchronize()
// back to last viewController
navigationController?.popToRootViewController(animated: true)
}else{
print("not num")
print("error alert push!!")
popErrorAlert()
}
}else {
print("nil")
print("editedRateHourly condition is nil")
popErrorAlert()
}
}
}
#IBAction func cannelInformationPage(_ sender: UIBarButtonItem) {
navigationController?.popToRootViewController(animated: true)
}
I want to create a new simple edit page. It's two problem for me that when I finish edition if-else will check the condition is correct or not and then save the data popToRootViewControlle. When I finish edition I click on "addInformation" BarButtonItem and I get UI wrong. the Other wrong is when I click on editField but I don't enter any condition. And then I click on "cannelInformationPage" UIBarButtonItem. It also get wrong.
It's what I get wrong
wrong information
Because it returns Bool
_ = navigationController?.popToRootViewController(animated: true)
_ = self.navigationController?.popViewController(animated: true)
If you want to come back to last view controller than you can try above line, hope its work for you.
I have just started using Digits - Twitter API for Phone Number verification, but it seems I'm unable to read the user's Phone number, I'm not sure if there is a function for that or so, but after reading a while I knew that I can do that with a Call back after successful phone verification but no explanation for that !
AuthConfig.Builder authConfigBuilder = new AuthConfig.Builder()
.withAuthCallBack(callback)
.withPhoneNumber(phoneNumberOrCountryCodeFromMyActivity)
found this snippet but again not sure where to implement it.
HERE is my Action for the login button with phone verification:
fileprivate func navigateToMainAppScreen() {
performSegue(withIdentifier: "signedIn", sender: self)
}
#IBAction func tapped(_ sender: Any) {
let configuration = DGTAuthenticationConfiguration(accountFields: .defaultOptionMask)
configuration?.appearance = DGTAppearance()
configuration?.appearance.backgroundColor = UIColor.white
configuration?.appearance.accentColor = UIColor.red
// Start the Digits authentication flow with the custom appearance.
Digits.sharedInstance().authenticate(with: nil, configuration:configuration!) { (session, error) in
if session != nil {
// Navigate to the main app screen to select a theme.
self.navigateToMainAppScreen()
} else {
print("Error")
}
}
}
So I found the answer after digging a lot more in Digits Documentations and it was pretty simple, I had to add:
print(session.phoneNumber)
print(session.userID)
In the didTap function, so the complete code will be:
#IBAction func tapped(_ sender: Any) {
let configuration = DGTAuthenticationConfiguration(accountFields: .defaultOptionMask)
configuration?.appearance = DGTAppearance()
configuration?.appearance.backgroundColor = UIColor.white
configuration?.appearance.accentColor = UIColor.red
// Start the Digits authentication flow with the custom appearance.
Digits.sharedInstance().authenticate(with: nil, configuration:configuration!) { (session, error) in
if session != nil {
//Print Data
print(session?.phoneNumber)
print(session?.userID)
// Navigate to the main app screen to select a theme.
self.navigateToMainAppScreen()
} else {
print("Error")
}
}
}
Here is the Reference I have used:
https://docs.fabric.io/apple/examples/cannonball/index.html#sign-in-with-digits