MFMailComposeViewController#91
Conversation
Added MFMailComposeViewController. Users are now able to send emails to shelters without exiting app.
WERUreo
left a comment
There was a problem hiding this comment.
Not bad for your first commit! If you have any questions about the comments I've left, just ask. :)
|
|
||
| func configureMailController() -> MFMailComposeViewController { | ||
| let mailComposerVC = MFMailComposeViewController() | ||
| let emailString = pet?.contact.email |
There was a problem hiding this comment.
You might want to do an if check on the email to make sure it isn't an empty string before trying to compose an email. I've noticed from the API responses that the email field is not always filled out.
There was a problem hiding this comment.
In fact, that being the case, you might also want to make the return type optional, so that you can check for it later on when you are about to try presenting the view controller.
| let sectionNumber = indexPath.section | ||
| let rowNumber = indexPath.row | ||
| if sectionNumber == 3 && rowNumber == 1 { | ||
| let mailComposeViewController = configureMailController() |
There was a problem hiding this comment.
If the return type for configureMailController() is optional like I suggested above, you can wrap all of this code in an if let and only try to present the controller if there is actually an email address.
| @@ -1,8 +0,0 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
There was a problem hiding this comment.
Make sure that this file isn't getting removed in your commit. The apikey.plist.example needs to remain in the repo for others to use if they want to develop for the project.
There was a problem hiding this comment.
Got it. I might need help doing this later, but I'll reach out to you or John in regards to this. Sorry about the hiatus by the way, looking to fix up the email feature this month.
|
|
||
| //////////////////////////////////////////////////////////// | ||
| // MARK: - UITableViewDataSource | ||
| //////////////////////////////////////////////////////////// |
There was a problem hiding this comment.
This MARK section isn't needed, because you're already under the existing MARK section for the UITableViewDataSource. Just push the beginning of the function underneath that comment line just above where you added this.
There was a problem hiding this comment.
Got it, just removed it.
|
|
||
| let sectionNumber = indexPath.section | ||
| let rowNumber = indexPath.row | ||
| if sectionNumber == 3 && rowNumber == 1 { |
There was a problem hiding this comment.
I get what you're doing here, and this works as the table view is currently set up, but this is probably not the best approach. You probably want to avoid using "magic numbers" like this. At the VERY least, I would define constants near the top of the file to make it easier to change these values if the need ever arose, but I actually have a more robust solution for this if you're interested in taking a look.
There was a problem hiding this comment.
I'd be down to look at the solution you have currently since I'm having issues figuring out how to go about selecting the email row specifically. I only did it this way for the time being since all the pets have the same number of cells but of course that's subject to change in the future.
There was a problem hiding this comment.
OK, I'll push up a separate pull request with what I came up with and link it to you on Slack. I'll be happy to go over with you also if you want.
There was a problem hiding this comment.
For now, let's just leave this in here like this, only because I don't want you to have to wait on me. If you could, though, could you add a TODO comment here? Something like:
// TODO: Refactor this approach to avoid using magic numbersor something to that effect.
WERUreo
left a comment
There was a problem hiding this comment.
There's also still a couple of things from my first review that need to be addressed, including putting the apikey.plist.example back, for one.
| INFOPLIST_FILE = "PetAdoption-iOS/Info.plist"; | ||
| LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; | ||
| PRODUCT_BUNDLE_IDENTIFIER = com.cfo.petadoption; | ||
| PRODUCT_BUNDLE_IDENTIFIER = com.lhaquebaruma.petadoption; |
There was a problem hiding this comment.
Looks like you forgot to set the bundle identifier back again heh
There was a problem hiding this comment.
I'll be sure to set it to cfo before I push the updates to git
| // } | ||
| // } | ||
| // } | ||
| // |
There was a problem hiding this comment.
Typically I would say not to leave commented out code like this in. It's fine for now since I know you're working on the phone number issue next.
| if sectionNumber == 3 && rowNumber == 1 { | ||
| let mailComposeViewController = configureMailController() | ||
| if MFMailComposeViewController.canSendMail() { | ||
| self.present((mailComposeViewController)!, animated: true, completion: nil) |
There was a problem hiding this comment.
The idea with making the return from configureMailController() be optional was that you could use an if let and avoid force unwrapping it like you're doing. Something more like
if let mailComposeViewController = configureMailController() {
if MFMailComposeViewController.canSendMail() {
self.present(mailComposeViewController, animated: true, completion: nil)
} else {
displayEmailError()
}
}There was a problem hiding this comment.
It's been a while since I looked over at this! I actually meddled with the solution you gave and it works except that all the cells available become active and end up triggering the mailComposeVC. How should I go about preventing that?
There was a problem hiding this comment.
Do you mean implementing the above snippet of code? I just made that change locally (it's not that different than what you currently had there) and it seems to only be trying to compose mail on the mail row.
| // If the return type for configureMailController() is optional like I suggested above, | ||
| // you can wrap all of this code in an if let and only try to | ||
| // present the controller if there is actually an email address. | ||
| // |
There was a problem hiding this comment.
These look like the comments I made in my last review hehe... You can go ahead and remove these.
|
|
||
| let sectionNumber = indexPath.section | ||
| let rowNumber = indexPath.row | ||
| if sectionNumber == 3 && rowNumber == 1 { |
There was a problem hiding this comment.
For now, let's just leave this in here like this, only because I don't want you to have to wait on me. If you could, though, could you add a TODO comment here? Something like:
// TODO: Refactor this approach to avoid using magic numbersor something to that effect.
Users now able to write to shelters without exiting app using MFMailComposeVC.