Posts

Post not yet marked as solved
4 Replies
2.4k Views
I wanted to know how would I set up Apple Pay in my app, and also in-app purchases. I already have the prices I want. So how would I do this? I have my app set up so you select a type of ride and ride length then it takes you to a PriceView where it shows what you selected and how much it cost. I want it so that when you are in the PriceView and you tap the book button it asks you to pay.
Posted
by Joel14.
Last updated
.
Post marked as solved
9 Replies
4.5k Views
I have a label with a minus and plus button beside it. What I want it to do is increment the value of the label by 1 if the plus button is tapped, and subtract 1 if the minus button is tapped.
Posted
by Joel14.
Last updated
.
Post marked as solved
6 Replies
2.6k Views
I have a UIImageView and four buttons below it. Once the user taps one of the buttons it sets the image in the image view. The problem is I want to add constraints to the images in the image view. I added the images programmatically the code for one of the buttons looks like this:overridefunc viewDidLoad() { super.viewDidLoad() let defaults = UserDefaults.standard goldImageView.image = UIImage(named: "gold with Text" } @IBAction func gold(_ sender: Any) { goldImageView.image = UIImage(named: "gold with Text") }
Posted
by Joel14.
Last updated
.
Post marked as solved
17 Replies
4.9k Views
I am having trouble with my app. The problem I am having is that when I leave a text field empty I want it to have a pop-up message that says empty text field and I want it to stop the segue from moving to the next screen. What is happening is it is showing the pop-up message of the empty text field but it still moves to the next screen. This is the code that I currently have: let firstNameAlert : UIAlertView = UIAlertView(title: "Blank Text Field", message: "Please fill in first name.", delegate: nil, cancelButtonTitle: "OK") let lastNameAlert : UIAlertView = UIAlertView(title: "Blank Text Field", message: "Please fill in last name.", delegate: nil, cancelButtonTitle: "OK") let emailAlert : UIAlertView = UIAlertView(title: "Blank Text Field", message: "Please fill in email.", delegate: nil, cancelButtonTitle: "OK") let addressAlert : UIAlertView = UIAlertView(title: "Blank Text Field", message: "Please fill in address.", delegate: nil, cancelButtonTitle: "OK") let phoneFromDefaults = defaults.object(forKey: "Phone Number") as? String if firstName.text == ""{ firstNameAlert.show() }else if lastName.text == ""{ lastNameAlert.show() }else if email.text == ""{ emailAlert.show() }else if addressLine1.text == ""{ addressAlert.show() }else{ performSegue(withIdentifier: "Create Account", sender: AnyObject.self) }
Posted
by Joel14.
Last updated
.
Post marked as solved
5 Replies
866 Views
I have four buttons. I wanted to know how I would make it so that when one button is tapped by the user it highlights that button and when the user taps another button it highlights that button and unhighlights the other button. Right now when I tap the button it does nothing to highlight the button. This is the current code that I have:extension UIButton { func setBackgroundColor(color: UIColor, forState: UIControl.State) { self.clipsToBounds = true // add this to maintain corner radius UIGraphicsBeginImageContext(CGSize(width: 1, height: 1)) if let context = UIGraphicsGetCurrentContext() { context.setFillColor(color.cgColor) context.fill(CGRect(x: 0, y: 0, width: 1, height: 1)) let colorImage = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() self.setBackgroundImage(colorImage, for: forState) } } } override func viewDidLoad() { super.viewDidLoad() let defaults = UserDefaults.standard // Do any additional setup after loading the view, typically from a nib. button1Button.titleLabel?.adjustsFontSizeToFitWidth = true button2Button.titleLabel?.adjustsFontSizeToFitWidth = true button3.titleLabel?.adjustsFontSizeToFitWidth = true button4.titleLabel?.adjustsFontSizeToFitWidth = true button1.setBackgroundImage(UIImage(named: "button1"), for: .normal) button1.setTitleColor(UIColor.black, for: .normal) button2.setBackgroundImage(UIImage(named: "button2"), for: .normal) button2.setTitleColor(UIColor.black, for: .normal) button3.setBackgroundImage(UIImage(named: "button3"), for: .normal) button3.setTitleColor(UIColor.black, for: .normal) //Set background for pre-natal massage button4.setBackgroundImage(UIImage(named: "button4"), for: .normal) button4.setTitleColor(UIColor.black, for: .normal) selectedMassageType = 1 buttonCatagory = .button2 highlightButtonType() button1.titleLabel?.textAlignment = NSTextAlignment.center button2.titleLabel?.textAlignment = NSTextAlignment.center button3.titleLabel?.textAlignment = NSTextAlignment.center button4.titleLabel?.textAlignment = NSTextAlignment.center } func highlightButtonType() { button1.setBackgroundImage(UIImage(named: "button1"), for: .normal) button2.setBackgroundImage(UIImage(named: "button2"), for: .normal) button3.setBackgroundImage(UIImage(named: "button3"), for: .normal) button4.setBackgroundImage(UIImage(named: "button4"), for: .normal) switch selectedButtonType { case button1.tag : button1.setBackgroundColor(color: UIColor.customWhite, forState: .highlighted) case button2.tag : button2.backgroundColor = UIColor.customBlue case button3.tag : button3.backgroundColor = UIColor.customBlue case button4.tag: button4.backgroundColor = UIColor.customBlue default: break } }
Posted
by Joel14.
Last updated
.
Post marked as solved
16 Replies
941 Views
I have a dictionary that I am trying to append information to but instead of appending to it just deletes the previous information. The dictionaries are in two different scopes. The dictionary name is personal info. They are on line 40 and 47. I tried doing personalInfo.append but it tells me that it has no member append. I am trying to save information to a database from to different views. This is the code that I have right now: @IBAction func sendPhoneAuthCode(_ sender: Any){ if let phoneNum = phoneNumber.text { // No more need to unwrap phoneNum later PhoneAuthProvider.provider().verifyPhoneNumber(phoneNum, uiDelegate: nil) { (verificationID, error) in // Sign in using the verificationID and the code sent to the user // … // if phoneNum == nil { if error != nil { print("verifyPhoneNumber went NOT OK") // REPLACE BY print self.present(alert, animated: true, completion: nil) DispatchQueue.global(qos: .userInitiated).async { let titre = " Missing Information " let detailMsg = "Please enter your phone number" let controller = UIAlertController(title: titre, message: detailMsg, preferredStyle: .alert) let okAction = UIAlertAction(title: "OK", style: UIAlertAction.Style.cancel) controller.addAction(okAction) DispatchQueue.main.async { self.present(controller, animated: true, completion: nil) } } return } else { print("verifyPhoneNumber went OK") // You have to test credential here, where do you do this ? } } } else { print("phoneNumber.text is nil") return } personalInfo = ["Phone Number" : phoneNumber.text] print("Setting userDefaults", verificationID) UserDefaults.standard.set(verificationID, forKey: "authVerificationID") } @IBAction func savePersonalInfo(_ sender: Any) { personalInfo = ["First Name" : firstName.text, "Last Name" : lastName.text, "Email" : email.text, "Address Line 1" : addressLine1.text, "Address Line 2" : addressLine2.text] let ref = Database.database().reference() ref.childByAutoId().setValue(personalInfo) }
Posted
by Joel14.
Last updated
.
Post not yet marked as solved
5 Replies
598 Views
I wanted to know how would I format someone's text that is entered into a text field. For example, I want if some enter their phone number 3101231234 it to look like this (310)123-1234 how would I be able to accomplish this.
Posted
by Joel14.
Last updated
.
Post not yet marked as solved
10 Replies
688 Views
I have an apple pay button and I wanted to know how I would segue to another view controller. The apple pay button is added programmatically. I already tried adding a performSegue and that did not work. This is the code for it once it is tapped:@objc private func applePayButtonTapped(sender: UIButton) { // Cards that should be accepted let paymentNetworks:[PKPaymentNetwork] = [.discover, .amex, .masterCard, .visa] if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) { let request = PKPaymentRequest() request.merchantIdentifier = "merchant.com.shiningdevelopers" request.countryCode = "CA" request.currencyCode = "CAD" request.supportedNetworks = paymentNetworks request.requiredShippingContactFields = [.name, .postalAddress] // This is based on using Stripe request.merchantCapabilities = .capability3DS let drive = PKPaymentSummaryItem(label: "Drive", amount: NSDecimalNumber(decimal: 1.00), type: .final) let tax = PKPaymentSummaryItem(label: "Tax", amount: NSDecimalNumber(decimal:1.00), type: .final) let total = PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(decimal:3.00), type: .final) request.paymentSummaryItems = [drive, tax, total] let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request) if let viewController = authorizationViewController { viewController.delegate = self present(viewController, animated: true, completion: nil) } } }
Posted
by Joel14.
Last updated
.
Post marked as solved
4 Replies
1.2k Views
I wanted to know how would I make so that when a user taps on a text field it clears the text already in it?
Posted
by Joel14.
Last updated
.
Post marked as solved
2 Replies
2.1k Views
I have an image that I want to add to my Xcode project to use as the tab bar item but I can only use the image as a .png file if I use anything else it automatically adds a white background to it. I want it to continue to have no background. How do I add the image to the assets.xcassets?
Posted
by Joel14.
Last updated
.
Post marked as solved
1 Replies
1k Views
I added an image to my tab bar with the size 50 x 50 and when I go to test the image all I get is a blue square how do I fix this?
Posted
by Joel14.
Last updated
.
Post not yet marked as solved
2 Replies
703 Views
I added Stripe to my app so that I can use Apple Pay. One problem that I am having is that I already have a view controller that shows the user the price. What I want to do is make so that when the Apple Pay pop up shows it shows the price of the price view controller. This is the code that I currently have:import UIKit import Stripe import CoreLocation class massagePriceView: UIViewController, PKPaymentAuthorizationViewControllerDelegate{ var price : Float? var category : MassageType? var length: massageLength? var dateOfMassage: Date? var physicalAddress : String = "" fileprivate var currentLocation : CLLocation? fileprivate let locationManager = CLLocationManager() @IBOutlet weak var massageTypePrice: UILabel! @IBOutlet weak var massageLengthPrice: UILabel! @IBOutlet weak var massageScheduledTime: UILabel! @IBOutlet weak var massagePriceTotal: UILabel! override func viewDidLoad() { super.viewDidLoad() print("viewDidLoad starts") if price != nil { massagePriceTotal.text = String(format: "$" + "%.2f", price!) } print("price is", massagePriceTotal.text!, price!) if category != nil {massageTypePrice.text = category!.description() } print("category is", massageTypePrice.text!, category!.description()) if length != nil { massageLengthPrice.text = length!.description() } print("length is", massageLengthPrice.text!, length!.description()) if dateOfMassage != nil { let formatter = DateFormatter() formatter.dateFormat = "MM/dd/yyyy hh:mm a" massageScheduledTime.text = formatter.string(from: dateOfMassage!) } addApplePayPaymentButtonToView() } private func addApplePayPaymentButtonToView() { let paymentButton = PKPaymentButton(paymentButtonType: .buy, paymentButtonStyle: .black) paymentButton.translatesAutoresizingMaskIntoConstraints = false paymentButton.addTarget(self, action: #selector(applePayButtonTapped(sender:)), for: .touchUpInside) view.addSubview(paymentButton) view.addConstraint(NSLayoutConstraint(item: paymentButton, attribute: .centerX, relatedBy: .equal, toItem: view, attribute: .centerX, multiplier: 1, constant: 0)) view.addConstraint(NSLayoutConstraint(item: paymentButton, attribute: .bottom, relatedBy: .equal, toItem: view, attribute: .bottom, multiplier: 1, constant: -25)) } @objc private func applePayButtonTapped(sender: UIButton) { // Cards that should be accepted let paymentNetworks:[PKPaymentNetwork] = [.discover, .amex, .masterCard, .visa] if PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: paymentNetworks) { let request = PKPaymentRequest() request.merchantIdentifier = "merchant.com.shiningdevelopers" request.countryCode = "CA" request.currencyCode = "CAD" request.supportedNetworks = paymentNetworks request.requiredShippingContactFields = [.name, .postalAddress] // This is based on using Stripe request.merchantCapabilities = .capability3DS let massage = PKPaymentSummaryItem(label: "Massage", amount: NSDecimalNumber(decimal: 1.00), type: .final) let tax = PKPaymentSummaryItem(label: "Tax", amount: NSDecimalNumber(decimal:1.00), type: .final) let total = PKPaymentSummaryItem(label: "Total", amount: NSDecimalNumber(decimal:3.00), type: .final) request.paymentSummaryItems = [massage, tax, total] let authorizationViewController = PKPaymentAuthorizationViewController(paymentRequest: request) if let viewController = authorizationViewController { viewController.delegate = self present(viewController, animated: true, completion: nil) } } } func paymentAuthorizationViewController(_ controller: PKPaymentAuthorizationViewController, didAuthorizePayment payment: PKPayment, handler completion: @escaping (PKPaymentAuthorizationResult) -> Void) { // Let the Operating System know that the payment was accepted successfully completion(PKPaymentAuthorizationResult(status: .success, errors: nil)) } func paymentAuthorizationViewControllerDidFinish(_ controller: PKPaymentAuthorizationViewController) { // Dismiss the Apple Pay UI dismiss(animated: true, completion: nil) } @IBAction func massagePriceViewBackButton(_ sender: Any) { dismiss(animated: true, completion: nil) } }
Posted
by Joel14.
Last updated
.
Post marked as solved
6 Replies
377 Views
I am having a problem with my tab bar controller. When I launch my app on my phone the tab bar controller the shows like it is supposed to and show the main page to let you select your drive and length and everything then you tap the continues button and it goes to the price view to show how much you are supposed to pay. But if you tap the back button to go back to the view to select the drive type and length the tab bar controller disappears right now I have the back button set up with just a show segue. How do I fix this problem?
Posted
by Joel14.
Last updated
.