Closed mhdostal closed 4 years ago
The same crash will occur when attempting to add a new feature and there is more than one feature layer in the map. When there is more than one FL, an AlertController is displayed allowing the user to select which FL to add the feature two. The default configuration in the app has only one FL, so this crash would not happen in that case.
There are two separate instances of the crash with the UIAlertViewController
: image source selection and Feature Layer selection.
The first, image source selection can be solved by changing the type of the UIAlertController
to .alert
from .actionSheet
. There is no barButtonItem in this case as it's triggered by tapping on the AddAttachment
row in a table. Also, the display of the action sheet is many layers removed, code-wise, from the table view so that passing in a source view and rect is not practical. So in this case, .alert
is the best bet. It will look like this:
The second, feature layer selection, can be handled either by making the UIAlertController
an .alert
OR by passing in a UIBarButtonItem
(which the actionSheet would be presented from on an iPad). The bar button item case would involve passing the sender
from the @IBAction
for the "add feature" button to the func userRequestsAddNewFeature(_ sender: Any)
method in MapViewController+LocationSelection
extension. The two options look like this:
Alert (both iPhone and iPad look the same):
BarButtonItem:
iPhone (this is unchanged from the original code):
iPad:
@esreli @mikewilburn Do either of you have a preference between using .alert
vs. UIBarButtonItem
in how the UI is presented?
Thanks for the consideration @mhdostal, but my recommendation here would mean very little. I defer to @esreli!
From a UI perspective, it would be my preference to keep the alert controller configured as an .actionSheet
, specifying the UIBarButtonItem
's view geometry as the source rect.
@mhdostal what do you think?
@esreli I'm cool with keeping the .actionSheet
for the layer selection and passing in the UiBarButtonItem
.
For the image source selection alert controller it's not so easy. There is no UIBarButtonItem
, only the "Add Attachments" table view cell. In the call stack below, ImagePickerPermissions.request(options:)
is where the UIAlertController
is presented. The action is initiated by a tap on the "Add Attachments" row, so that's would require passing a sourceView
and sourceRect
down more than one level deep.
#0 0x0000000104d304e0 in ImagePickerPermissions.request(options:) at /Users/mark1113/Development/OpenSourceApps/data-collection-ios/data-collection/data-collection/Utilities/ImagePickerPermissions.swift:181
#1 0x0000000104db58e0 in RichPopupViewController.attachmentsViewControllerDidRequestAddAttachment(_:) at /Users/mark1113/Development/OpenSourceApps/data-collection-ios/data-collection/data-collection/View Controllers/Rich Popup View Controllers/Rich Popup View Controller/RichPopupViewController+RichPopupAttachmentsViewControllerDelegate.swift:41
#2 0x0000000104db60b8 in protocol witness for RichPopupAttachmentsViewControllerDelegate.attachmentsViewControllerDidRequestAddAttachment(_:) in conformance RichPopupViewController ()
#3 0x0000000104de6af8 in RichPopupAttachmentsViewController.tableView(_:didSelectRowAt:) at /Users/mark1113/Development/OpenSourceApps/data-collection-ios/data-collection/data-collection/View Controllers/Rich Popup View Controllers/Rich Popup View Controller/RichPopupAttachmentsViewController/RichPopupAttachmentsViewController+UITableViewDelegate.swift:74
So for the image source selection alert controller, I'd say we switch to the .alert
option.
The action is initiated by a tap on the "Add Attachments" row, so that's would require passing a
sourceView
andsourceRect
down more than one level deep.
I see now what you're saying.
So for the image source selection alert controller, I'd say we switch to the
.alert
option.
I thought we might be able to avoid presenting the user with the notion of an alert, which (to me, at least) implies the user has reached a barrier, in favor of prompting them to take an action. It also appears we have way to present a modal .actionSheet
in any other style than .popover
. Without some sort of UI anchor, it looks like UIKit has forced our hand on this one.
Admittedly, amidst the other tasks i'm attending to simultaneously, I didn't investigate the issue as thoroughly as I would have needed to. I'm sorry & i'll do better next time.
In iOS 13 presenting the image source selection alert controller no longer crashes when using .actionSheet
without a UIBarButtonItem
or setting a sourceView/sourceRect
.
Verified in the v1.1.2 release.
When attempting to add an attachment to a new tree, tapping the "Add Attachments" row in the "Attachments" view crashes the app. The error shown in the log is:
The cause is the UIAlertController needs a rectangle to display the action sheet from on an iPad. This can happen either by the controller's
popoverPresentationController?.barButtonItem
or a combination ofpopoverPresentationController?.sourceView
andpopoverPresentationController?.sourceRect
properties.The solution is to provide a source Rect that the popover would display from (the cell's frame maybe?) or to switch to a different type of alert VC (maybe).
This is iPad-only; does not crash on an iPhone 8.
iPad Pro 10.5" iOS 12.4.1