Solved iOS SMS window always stays active and it is impossible to cancel it on iPhone
-
Hi all.
I need to register an own URL handler which handles my custom URL scheme as 'smsto'. In this scheme I use the custom URL which allows to transfer a custom pre-defined SMS body.
For this purpose I have created my URL handler ExtendedUrlHandler with following code:
... void ExtendedUrlHandler::registerSchemes() { QDesktopServices::setUrlHandler(QLatin1String(INSTAGRAM_SCHEME), this, "handleInstagramUrl"); QDesktopServices::setUrlHandler(QLatin1String(SMS_SCHEME), this, "handleSmsUrl"); } void ExtendedUrlHandler::unregisterSchemes() { QDesktopServices::unsetUrlHandler(QLatin1String(INSTAGRAM_SCHEME)); QDesktopServices::unsetUrlHandler(QLatin1String(SMS_SCHEME)); } ...
And then following method launch the native iPhone SMS dialer:
void ExtendedUrlHandler::handleSmsUrl(const QUrl &url) { qCWarning(EXTURL_HANDLER) << "Start pase url:" << url; QString smsScheme; QString smsPhone; QString smsBody; const auto isParsed = parseSmsUrl(url, &smsScheme, &smsPhone, &smsBody); if (!isParsed) return; UIWindow *window = qt_apple_sharedApplication().keyWindow; const auto messageViewController = [[[MFMessageComposeViewController alloc] init] autorelease]; if ([MFMessageComposeViewController canSendText]) { messageViewController.body = smsBody.toNSString(); messageViewController.recipients = [NSArray arrayWithObjects:smsPhone.toNSString(), nil]; messageViewController.messageComposeDelegate = nil; [window.rootViewController presentViewController:messageViewController animated:YES completion:nil]; } }
But a problem that I can't exit from the SMS dialer back to my application UI. It always show the SMS dialer, even I click to 'Cancel' button.
Could someone point me to the right way?
-
I fixed this now. Need just to use a delegate where rectore the application's UIView, see for example this.