Add a close request function to your app that requires confirmation.
1. From AppDesigner > Design View, right click the figure background, go down to "Callbacks", and select "Add CloseRequestFc function callback".
2. A UIFigureCloseRequest() function will be added in Code View. Add this to the function where app.UIFigure is the handle to your app figure.
YN = uiconfirm(app.UIFigure,'Do you want to close the app?', 'Close request');
if strcmpi(YN,'OK')
delete(app)
end