UIViewController present crash app


#1

Товарищи, выручайте! 2 дня бьюсь над проблемой, после нажатия на кнопку добавить картинку приложение вылетает

Код

func presentAction(configuration: AlertScreenConfiguration) {
let controller = UIAlertController(title: configuration.title,
message: configuration.message,
preferredStyle: .actionSheet)

    if configuration.actions.isEmpty {
        let action = UIAlertAction(title: "screen.alert.button.ok".localized(),
                                   style: .cancel) { _ in
                                    
                                    controller.dismiss(animated: true, completion: nil)
        }
        
        controller.addAction(action)
    } else {
        for actionConfig in configuration.actions {
            let action = UIAlertAction(title: actionConfig.title,
                                       style: actionConfig.style.value) { _ in
                                        actionConfig.handler?()
                                        
                                        controller.dismiss(animated: true, completion: nil)
            }
            
            controller.addAction(action)
        }
    }
    
    viewController.present(controller, animated: true, completion: nil)
    
}

После viewController.present(controller, animated: true, completion: nil) вылетает с ошибкой libc++abi.dylib: terminating with uncaught exception of type NSException

Функция при нажатии на кнопку

private func showImagePickerActionSheet() {
let configuration = AlertScreenConfiguration(title: nil, message: nil, style: .actionSheet)

    let cameraTitle = "screen.alert.button.camera".localized()
    let cameraAction = AlertScreenAction(title: cameraTitle, style: .default) { [weak self] in
        guard let strongSelf = self else { return }
        
        strongSelf.imagePickerModule = strongSelf.router.showCameraPicker(moduleOutput: strongSelf, allowsEditing: true)
    }
    
    let photoLibraryTitle = "screen.alert.button.photoLibrary".localized()
    let photoLibratyAction = AlertScreenAction(title: photoLibraryTitle, style: .default) { [weak self] in
        guard let strongSelf = self else { return }
        
        strongSelf.imagePickerModule = strongSelf.router.showGalleryPicker(moduleOutput: strongSelf, allowsEditing: true)
    }
    
    let cancelTitle = "button.title.cancel".localized()
    let cancelAction = AlertScreenAction(title: cancelTitle, style: .cancel, handler: nil)
    
    configuration.addAction(cameraAction)
    configuration.addAction(photoLibratyAction)
    configuration.addAction(cancelAction)
    
    router.presentAction(configuration: configuration)
}

Причем, заметил что ошибка только когда запускаю на iPad, на iPhone все нормально работает.


#2

Так подожди. У тебя ж controller это сам Alert. Зачем ты ему dismiss вызываешь? :thinking:


#3

но почему на iPhone не вылетает, а на iPad вылетает?


#4

Ну это второй вопрос. Хотя на выходных попробую поэксперементировать :slight_smile:


#5

Короче, ты там ActionSheet используешь. А в iPad надо использовать popover. Всплывающие плашки, иначе он будет на весь айпад колбасню растягивать. Поэтому и происходит креш с соответствующим месседжем.

You must provide either a sourceView and sourceRect or a barButtonItem.  If this information is not known when you present the alert controller, you may provide it in the UIPopoverPresentationControllerDelegate method -prepareForPopoverPresentation.'

#6

Привет! Спасибо за совет! Эта мысль меня тоже посетила, вечером доберусь до Xcode , проверю. Сообщения такого в консоли не было, появляется nsexception и выкидывает в appdelegate…


#7

Все было бы проще, если бы это был мой код, но это приложение которое затянул разработчик и родственник попросил довести его до ума, тяжко разбираться в чужом коде, ещё и баги фиксить надо…


#8

Нде. ну удачи. Сам недавно такой проект передал в свободное плаванье. Разработчика откровенно жаль, потому что ему придется погрузиться в код и дебри моего сознания =)))


#9

Все исправил! Спасибо за советы! Дело было в модальном выводе.