UIAlertController ejemplo
func onImagePressed(_ sender: UITapGestureRecognizer) {
//Create the AlertController and add Its action like button in Actionsheet
let aSheet: UIAlertController = UIAlertController(title: "", message: "selectImageMethod".localized, preferredStyle: .actionSheet)
let cancelActionButton = UIAlertAction(title: "Cancel".localized, style: .cancel) { _ in
print("cancel")
}
aSheet.addAction(cancelActionButton)
let cameraAction = UIAlertAction(title: "camera".localized, style: .default)
{ _ in
let imagePicker = UIImagePickerController()
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
aSheet.addAction(cameraAction)
let deleteActionButton = UIAlertAction(title: "gallery".localized, style: .default)
{ _ in
let imagePicker = UIImagePickerController()
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
aSheet.addAction(deleteActionButton)
//necesario para iPad
aSheet.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem;
//o asignar una view
//aSheet.popoverPresentationController?.sourceView = self.view
//let bounds = self.btnMenu.bounds;
//aSheet.popoverPresentationController?.sourceRect = CGRect(x: bounds.origin.x, y: (bounds.origin.y+bounds.height), width: bounds.width, height: bounds.height);
self.present(aSheet, animated: true, completion: nil)
}
-(void) showRatingAppDialog{
BOOL showPopUp = [PreferenceUtils getShowRatingPopup];
int executionCounter = [PreferenceUtils getExecutionCounter];
executionCounter = executionCounter + 1;
[PreferenceUtils setExecutionCounter:executionCounter];
if (showPopUp) {
if (executionCounter % CHECK_RATING_EVERY == 0) {
UIAlertController * view= [UIAlertController
alertControllerWithTitle:NSLocalizedString(@"rate_us", nil)
message:NSLocalizedString(@"rate_thanks_for_using", nil)
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* rateNow = [UIAlertAction
actionWithTitle:NSLocalizedString(@"rate", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
NSString* url = [NSString stringWithFormat: @"%@%@", ITUNES_RATING_URL, APP_IDENTIFIER];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
}];
UIAlertAction* noThanks = [UIAlertAction
actionWithTitle:NSLocalizedString(@"rate_no_thanks", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[PreferenceUtils setShowRatingPopup:NO];
[view dismissViewControllerAnimated:YES completion:nil];
}];
UIAlertAction* rateLater = [UIAlertAction
actionWithTitle:NSLocalizedString(@"rate_maybe_later", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES completion:nil];
}];
[view addAction:rateNow];
[view addAction:noThanks];
[view addAction:rateLater];
/////////////////////////////////////
//NECESARIO PARA QUE NO FALLE EN IPAD
//Las dos primeras coordenadas se pueden modificar por la ubicación de algún botón
view.popoverPresentationController.sourceView = self.view;
view.popoverPresentationController.sourceRect = CGRectMake(self.view.bounds.size.width / 2.0, self.view.bounds.size.height, 1.0, 1.0);
/////////////////////////////////////
[self presentViewController:view animated:YES completion:nil];
}
}
}