D11.2 iOS15.6 Crash after sms message sent or canceled when returning to app

When using TTMSFMXNativeMFMessageComposeViewController with a simple app (attached) the app will crash both upon sending or cancelling sms when returning to the app

iOSSMS.zip (13.4 KB)

Stack Trace...
System._DbgExcNotify(int, void*, System.SmallString<(unsigned char)255>, void, void*)
System.NotifyReRaise(System.TObject*, void*)($000000028235c500,$00000001056cef30)
System.RaiseAtExcept(System.TObject*, void*)($000000028235c500,$00000001056cef30)
:0000000104F097E8 System::Internal::Excutils::SignalConverter(NativeUInt, NativeUInt, NativeUInt)
Fmx.Tmsnativemfmessagecomposeviewcontroller.TMFMessageComposeViewControllerDelegate.messageComposeViewController(System.DelphiInterface<Fmx.Tmsnativeuicore.MFMessageComposeViewController>, unsigned int)($000000028233a580,0)
:00000001056D0520 DispatchToDelphi
:00000001A0905AC0 -[MFMessageComposeViewController smsComposeControllerCancelled:]
:000000018C45C5C8 -[CKSMSComposeController smsComposeControllerCancelled]
:000000018C4789D8 -[CKSMSComposeRemoteViewController smsComposeControllerCancelled]
:00000001804BDDD0 invoking

:00000001804D9EA8 -[NSInvocation invoke]
:00000001801F0094 _dispatch_client_callout
:00000001801C8048 _dispatch_block_invoke_direct$VARIANT$armv81
:00000001916942AC FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
:00000001916937C0 -[FBSSerialQueue _targetQueue_performNextIfPossible]
:0000000191697960 -[FBSSerialQueue _performNextFromRunLoopSource]
:00000001805504FC CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
:000000018056062C __CFRunLoopDoSource0
:00000001804A2834 __CFRunLoopDoSources0
:00000001804A7F08 __CFRunLoopRun
:00000001804BB250 CFRunLoopRunSpecific
:00000001A0FEE988 GSEventRunModal
:0000000182CBBA94 -[UIApplication _run]
:0000000182A54FD4 UIApplicationMain
:00000001055268AC Fmx::Platform::Ios::TPlatformCocoaTouch::Run()
:0000000105526834 __stub_in200s__ZN3Fmx8Platform3Ios19TPlatformCocoaTouch3RunEv
:00000001055E6678 Fmx::Forms::TApplication::Run()
main(1,$000000016af2fad8,$000000016af2fae8,$000000016af2fb48)
:0000000106D844D0 start

Can you try commenting this code:

  if Assigned(FMessageComposeViewController.FMessageComposeViewController) then
  begin
    FMessageComposeViewController.FMessageComposeViewController.dismissModalViewControllerAnimated(True);
    FMessageComposeViewController.FMessageComposeViewController.removeFromParentViewController;
    FMessageComposeViewController.FMessageComposeViewController.release;
    FMessageComposeViewController.FMessageComposeViewController := nil;
  end;

I tried that, but popup sms screen no longer closes when taping cancel. I uncommented that code again and I placed some code after the MessageComposeViewController.Show, and I see that it returns back to my app before the modal sms popup is even displayed, so my finally would have freed the MessageComposeViewController. Seems the behaviour has changed. I can workaround this by creating
the MessageComposeViewController with the form as the owner and not free it manually.
Is this expected behaviour?

I spoke too soon, although not freeing the MessageComposeViewController works in my sample app I still have a crash in my actual app.

Stack Trace

System._DbgExcNotify(int, void*, System.SmallString<(unsigned char)255>, void, void*)
System.NotifyReRaise(System.TObject*, void*)($0000000283583bb0,$0000000100a45894)
System._RaiseAtExcept(System.TObject*, void*)($0000000283583bb0,$0000000100a45894)
:0000000100731464 System::Internal::Excutils::SignalConverter(NativeUInt, NativeUInt, NativeUInt)
Fmx.Utils.TNonReentrantHelper.Execute(bool&, System.DelphiInterface<System.Sysutils.TProc>)($00000001026cce50,$00000000000001c8,$0000000280de71a8)
:0000000100E23EBC Fmx::Forms::TCommonCustomForm::SetFocused(System::DelphiInterfaceFmx::Types::IControl)
Fmx::Virtualkeyboard::Ios::TKeyboardEventHandler::HideVirtualKeyboard()
Fmx::Virtualkeyboard::Ios::TKeyboardEventHandler::KeyboardWillHide(void*)
:0000000101E981B0 DispatchToDelphi
:00000001806CE2E8 CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER
:00000001807638E4 ___CFXRegistrationPost_block_invoke
:0000000180738C04 _CFXRegistrationPost
:00000001806E3070 _CFXNotificationPost
:0000000181DD304C -[NSNotificationCenter postNotificationName:object:userInfo:]
:0000000182E48BD0 __68-[UIInputWindowController postValidatedStartNotifications:withInfo:]_block_invoke
:0000000182E55010 -[UIInputWindowController postValidatedStartNotifications:withInfo:]
:000000018367D7DC __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.985
:0000000182E19724 +[UIView(UIViewAnimationWithBlocksPrivate) _modifyAnimationsWithPreferredFrameRateRange:updateReason:animations:]
:0000000182B53128 +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:]
:0000000182F366A4 -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
:0000000182E56714 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]
:0000000182E7837C -[UIInputWindowController setInputViewSet:]
:0000000182E0DC88 -[UIInputWindowController performOperations:withAnimationStyle:]
:0000000182DEADF0 -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:]
:0000000182E7DC6C -[UIKeyboardSceneDelegate setInputViews:animationStyle:]
:0000000182BEA070 -[UIKeyboardSceneDelegate setInputViews:animated:]
:0000000182CA3C10 -[UIKeyboardSceneDelegate setInputViews:]
:0000000183401F2C __71-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:]_block_invoke.700
:0000000182CD3114 -[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:]
:0000000182BA8CDC -[UIKeyboardSceneDelegate _reloadInputViewsForResponder:]
:0000000182E247E4 -[UIResponder _finishResignFirstResponder]
:0000000182BE8DF4 -[UIResponder resignFirstResponder]
:0000000182D223D0 -[UIView(UITextField) endEditing:]
:0000000182C85844 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke
:000000018302AA00 -[UIPresentationController runTransitionForCurrentState]
:0000000182C705DC -[UIPresentationController _dismissWithAnimationController:interactionController:target:didEndSelector:]
:0000000182C979F0 -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
:0000000182E2C550 -[UIViewController dismissViewControllerWithTransition:from:completion:]
:0000000182D727B0 -[UIViewController dismissViewControllerWithTransition:completion:]
:0000000182D72630 -[UIViewController dismissViewControllerWithTransition:completion:]
:0000000101E97FC0 DispatchToImport
Fmx.Tmsnativemfmessagecomposeviewcontroller.TMFMessageComposeViewControllerDelegate.messageComposeViewController(System.DelphiInterface<Fmx.Tmsnativeuicore.MFMessageComposeViewController>, unsigned int)($00000002835ba710,0)
:0000000101E981B0 DispatchToDelphi
:00000001A0B0DAC0 -[MFMessageComposeViewController smsComposeControllerCancelled:]
:000000018C6645C8 -[CKSMSComposeController smsComposeControllerCancelled]
:000000018C6809D8 -[CKSMSComposeRemoteViewController smsComposeControllerCancelled]
:00000001806C5DD0 invoking

:00000001806E1EA8 -[NSInvocation invoke]
:00000001803F8094 _dispatch_client_callout
:00000001803D0048 _dispatch_block_invoke_direct$VARIANT$armv81
:000000019189C2AC FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
:000000019189B7C0 -[FBSSerialQueue _targetQueue_performNextIfPossible]
:000000019189F960 -[FBSSerialQueue _performNextFromRunLoopSource]
:00000001807584FC CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
:000000018076862C __CFRunLoopDoSource0
:00000001806AA834 __CFRunLoopDoSources0
:00000001806AFF08 __CFRunLoopRun
:00000001806C3250 CFRunLoopRunSpecific
:00000001A11F6988 GSEventRunModal
:0000000182EC3A94 -[UIApplication _run]
:0000000182C5CFD4 UIApplicationMain
:0000000100D5EB08 Fmx::Platform::Ios::TPlatformCocoaTouch::Run()
:0000000100D5EA90 __stub_in200s__ZN3Fmx8Platform3Ios19TPlatformCocoaTouch3RunEv
:0000000100E1E9CC Fmx::Forms::TApplication::Run()
main(1,$000000016f70bad8,$000000016f70bae8,$000000016f70bb48)
:00000001062F04D0 start

Found the other exception is due to using the FNCTaskDialog prior to calling MessageComposeViewController.Show. Attached example shows with and without Task Dialog
iosSMS2.zip (13.9 KB)

Stack Trace

System._DbgExcNotify(int, void*, System.SmallString<(unsigned char)255>, void, void*)
System.NotifyReRaise(System.TObject*, void*)($000000028307a710,$00000001025081e4)
System._RaiseAtExcept(System.TObject*, void*)($000000028307a710,$00000001025081e4)
:00000001021FAEE0 System::Internal::Excutils::SignalConverter(NativeUInt, NativeUInt, NativeUInt)
Fmx.Utils.TNonReentrantHelper.Execute(bool&, System.DelphiInterface<System.Sysutils.TProc>)($0000000103213a10,$00000000000001c8,$00000002806bd8e8)
:00000001028E4B34 Fmx::Forms::TCommonCustomForm::SetFocused(System::DelphiInterfaceFmx::Types::IControl)
Fmx::Virtualkeyboard::Ios::TKeyboardEventHandler::HideVirtualKeyboard()
Fmx::Virtualkeyboard::Ios::TKeyboardEventHandler::KeyboardWillHide(void*)
:0000000102DB5560 DispatchToDelphi
:00000001806CE2E8 CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER
:00000001807638E4 ___CFXRegistrationPost_block_invoke
:0000000180738C04 _CFXRegistrationPost
:00000001806E3070 _CFXNotificationPost
:0000000181DD304C -[NSNotificationCenter postNotificationName:object:userInfo:]
:0000000182E48BD0 __68-[UIInputWindowController postValidatedStartNotifications:withInfo:]_block_invoke
:0000000182E55010 -[UIInputWindowController postValidatedStartNotifications:withInfo:]
:000000018367D7DC __77-[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]_block_invoke.985
:0000000182E19724 +[UIView(UIViewAnimationWithBlocksPrivate) _modifyAnimationsWithPreferredFrameRateRange:updateReason:animations:]
:0000000182B53128 +[UIView _setupAnimationWithDuration:delay:view:options:factory:animations:start:animationStateGenerator:completion:]
:0000000182F366A4 -[UIInputViewAnimationStyle launchAnimation:afterStarted:completion:forHost:fromCurrentPosition:]
:0000000182E56714 -[UIInputWindowController moveFromPlacement:toPlacement:starting:completion:]
:0000000182E7837C -[UIInputWindowController setInputViewSet:]
:0000000182E0DC88 -[UIInputWindowController performOperations:withAnimationStyle:]
:0000000182DEADF0 -[UIKeyboardSceneDelegate setKeyWindowSceneInputViews:animationStyle:]
:0000000182E7DC6C -[UIKeyboardSceneDelegate setInputViews:animationStyle:]
:0000000182BEA070 -[UIKeyboardSceneDelegate setInputViews:animated:]
:0000000182CA3C10 -[UIKeyboardSceneDelegate setInputViews:]
:0000000183401F2C __71-[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:]_block_invoke.700
:0000000182CD3114 -[UIKeyboardSceneDelegate _reloadInputViewsForKeyWindowSceneResponder:]
:0000000182BA8CDC -[UIKeyboardSceneDelegate _reloadInputViewsForResponder:]
:0000000182E247E4 -[UIResponder _finishResignFirstResponder]
:0000000182BE8DF4 -[UIResponder resignFirstResponder]
:0000000182D223D0 -[UIView(UITextField) endEditing:]
:0000000182C85844 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke
:000000018302AA00 -[UIPresentationController runTransitionForCurrentState]
:0000000182C705DC -[UIPresentationController _dismissWithAnimationController:interactionController:target:didEndSelector:]
:0000000182C979F0 -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
:0000000182E2C550 -[UIViewController dismissViewControllerWithTransition:from:completion:]
:0000000182D727B0 -[UIViewController dismissViewControllerWithTransition:completion:]
:0000000182D72630 -[UIViewController dismissViewControllerWithTransition:completion:]
:0000000102DB5370 DispatchToImport
Fmx.Tmsnativemfmessagecomposeviewcontroller.TMFMessageComposeViewControllerDelegate.messageComposeViewController(System.DelphiInterface<Fmx.Tmsnativeuicore.MFMessageComposeViewController>, unsigned int)($00000002830dc640,0)
:0000000102DB5560 DispatchToDelphi
:00000001A0B0DAC0 -[MFMessageComposeViewController smsComposeControllerCancelled:]
:000000018C6645C8 -[CKSMSComposeController smsComposeControllerCancelled]
:000000018C6809D8 -[CKSMSComposeRemoteViewController smsComposeControllerCancelled]
:00000001806C5DD0 invoking

:00000001806E1EA8 -[NSInvocation invoke]
:00000001803F8094 _dispatch_client_callout
:00000001803D0048 _dispatch_block_invoke_direct$VARIANT$armv81
:000000019189C2AC FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK
:000000019189B7C0 -[FBSSerialQueue _targetQueue_performNextIfPossible]
:000000019189F960 -[FBSSerialQueue _performNextFromRunLoopSource]
:00000001807584FC CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION
:000000018076862C __CFRunLoopDoSource0
:00000001806AA834 __CFRunLoopDoSources0
:00000001806AFF08 __CFRunLoopRun
:00000001806C3250 CFRunLoopRunSpecific
:00000001A11F6988 GSEventRunModal
:0000000182EC3A94 -[UIApplication _run]
:0000000182C5CFD4 UIApplicationMain
:000000010281F7C0 Fmx::Platform::Ios::TPlatformCocoaTouch::Run()
:000000010281F748 __stub_in200s__ZN3Fmx8Platform3Ios19TPlatformCocoaTouch3RunEv
:00000001028DF644 Fmx::Forms::TApplication::Run()
main(1,$000000016dc3fad8,$000000016dc3fae8,$000000016dc3fb48)
:00000001052404D0 start

Can you try calling it from another thread?

I tried in another thread but I get an AV when calling MessageComposeViewController.Show Can you give me an example of how you would do it?

I did this..
TThread.CreateAnonymousThread(
procedure
begin
SendSMS(edtPhoneNo.Text,'Test message');
end).Start;

So, without the taskdialog there are no problems? Can you send a small test app?

Hi,

We've investigated this and applied a fix for TTMSFNCTaskDialog. Your sample project worked correctly after that here. The changes will be available with the next update.

Thank you, Just to clarify, there were two separate issues here, the task dialog you have addressed. The original issue in the first sample project was a crash returning from the native sms form back to the app, this was caused by MessageComposeViewController.Show now being non modal and returning back to the calling code and in my case would free the MessageComposeViewController. As mentioned I can work around this by not freeing the MessageComposeViewController until app closed. You will see that I have done this in the second sample project to highlight the task dialog issue.

Is it expected that calling MessageComposeViewController.Show is now non-modal or does this also need to be fixed to make it modal again?