alex_lip
alex_lipJan. 14, 2018, 2:15 p.m.

Development on Qt for iOS

Content

Preamble

The most democratic country in the world has created the most totalitarian operating system. Therefore, if you want to test your software on an iPad or IPhone, you must register with https://developer.apple.com/ as a developer. At the first stage, you do not have to pay money. Good Uncle Jobs will give you a certificate, for use to test your device, for a period of 7 (seven) days. At the end of the certificate, your software will not start and it will need to be downloaded again from the computer. If you want to install your software on another person's device - its apple ID will need to be written in the same way in Xcode as yours.


Problems

To study Qt, I decided to develop a mobile workplace for the workflow for the test task. Because the documents can be in the form of word, pdf, jpg, etc. I naturally need after downloading them from the server something to open them. Qt has a wonderful design

QDesktopServices :: openUrl ( QUrl :: fromLocalFile ( QStandardPaths :: writableLocation ( QStandardPaths :: GenericDataLocation ) + "/temp_esd/file." + file_ext ));
// File _ ext I pull out according to the MIME type
if ( head == "Content-Type" ) {
    if ( content_from_url == "image/jpeg" )
        file_ext = "jpg";
    else if ( content_from_url == "application/pdf" )
        file_ext = "pdf";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.wordprocessingml.document" )
        file_ext = "docx";
    else if ( content_from_url == "application/msword" )
        file_ext = "doc";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" )
        file_ext = "xlsx";
    else if ( content_from_url == "application/vnd.ms-excel" )
        file_ext = "xls";
    else if ( content_from_url == "application/vnd.oasis.opendocument.text" )
        file_ext = "odt";
    else if ( content_from_url == "application/vnd.oasis.opendocument.spreadsheet" )
        file_ext = "ods";
    else if ( content_from_url == "application/octet-stream" )
        file_ext = "7z";
    else if ( content_from_url == "video/x-msvideo" )
        file_ext = "avi";
    else if ( content_from_url == "image/bmp" )
        file_ext = "bmp";
    else if ( content_from_url == "application/cdr" )
        file_ext = "cdr";
    else if ( content_from_url == "image/gif" )
        file_ext = "gif";
    else if ( content_from_url == "video/quicktime" )
        file_ext = "mov";
    else if ( content_from_url == "audio/mpeg" )
        file_ext = "mp3";
    else if ( content_from_url == "image/png" )
        file_ext = "png";
    else if ( content_from_url == "application/vnd.ms-powerpoint" )
        file_ext = "ppt";
    else if ( content_from_url == "application/vnd.openxmlformats-officedocument.presentationml.presentation" )
        file_ext = "pptx";
    else if ( content_from_url == "application/x-rar-compressed" )
        file_ext = "rar" ;
    else if ( content_from_url == "application/rtf" )
        file_ext = "rtf";
    else if ( content_from_url == "image/tiff" )
        file_ext = "tif";
    else if ( content_from_url == "text/plain" )
        file_ext = "txt" ;
    else if ( content_from_url == "audio/x-ms-wma" )
        file_ext = "wma";
    else if ( content_from_url == "application/zip" )
        file_ext = "zip";
}

But in iOS - in accordance with the recently adopted security standards it is forbidden to open a local URL in one application by running another one. Therefore, under IOS, the use of this construction caused an error

this plugin does not support

First I went in the direction of using Info.plist - especially since under iOS it is still needed. Registered in section

<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>ms-word</string> 
        <string>ms-powerpoint</string> 
        <string>ms-excel</string>
    </array>

But this works only if the files are opened NOT locally - but on the Internet link. After further study of the problem, I came across the article https://code.tutsplus.com/tutorials/ios-sdk-previewing-and-opening-documents--mobile-15130 which describes how to use the UIDocumentInteractionController to open files in the sandbox of the ios application . Also thank you very much Ekkehard Gentz for a completely wonderful blog, which details the use of the above function in Qt.

Solution

And so we have a MAC MINI for compiling source and IPAD for testing. On the MAC MINI install QT. During the installation you will be offered to download XCODE - we agree. Everything is perfectly established. Next, in Xcode - Preferences - Accounts, add your Apple account and request a certificate (via Manage Certificates). Naturally, you must first register on the Apple website as a developer. Next, connect your IPAD and in the Settings - Developer - UI AUTOMATION - enable Enable UI Automation. Thus, we have transferred the iPad to the debugged mode.

In Xcode - Window - Devices and Simulators, you can check your connected device. Of course, during the connection you will be asked a couple of times about the trust of the computer to the device and the device of the computer - say YES.

In the Qt in the project file, add the following section

ios {
OBJECTIVE_SOURCES += ios/iosshareutils.mm \
ios/docviewcontroller.mm

QMAKE_INFO_PLIST = ios/Info.plist

LIBS += - framework UIKit
}

In this section we specify the location of Info.plist - this is a textual configuration file that you can edit manually.

OBJECTIVE_SOURCES are our files on OBJECTIVE- C

The LIBS directive is probably outdated. But I did not remove it.

In the sources themselves it is very convenient to use the directive

#if defined( Q_OS_IOS )

QString temp_url= QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/temp_esd/file." +file_ext;
qDebug() << "path_file " << temp_url;
IosShareUtils ios;
ios.viewFile(temp_url, "View File" , "application/pdf" , 21 );

#else
QDesktopServices :: openUrl ( QUrl :: fromLocalFile ( QStandardPaths :: writableLocation ( QStandardPaths :: GenericDataLocation ) + "/temp_esd/file." + file_ext ));
#endif

You can see the source code in the blog https://blog.qt.io/blog/2017/12/01/sharing-files-android-ios-qt-app/

In general, after the source texts are ready, we proceed to the de-file. Please note that in Qt Creator when you release on Qt 5.10 for iOS, the green dot on the right below the icon of the phone with the apple is burning. Hover over it and see the information about the device and whether it works in developer mode. After that, we compile the sources and try to upload them to the phone. From the first time does not work. Go to the Release folder and open the Xcode project of our application. At the top, where the name of your circuit is, select the active circuit on the device that is connected to the computer. Then click on the "Build and then run the current scheme" icon. But that is not all. Your application icon will appear on your device, but it will not start. Or it will start, but it will close quickly. Open the Ipad - go to settings - basic - device management - software developer - choose your apple id - then we say that we trust this developer. After all these operations, you can safely unplug the application directly from Qt Creator.

Thanks to all of the internet who patiently answered my stupid questions. And God will forgive those who tried to shake me off money. It seems to me - some kind of altruism should be present for every professional.

We recommend hosting TIMEWEB
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.

Do you like it? Share on social networks!

BlinCT
  • Jan. 14, 2018, 2:28 p.m.

Вот честно, на сколько же муторно под огрызок что то делать. Куча проблем)
А вод линь или под Андроид все просто и тривиально))

Comments

Only authorized users can post comments.
Please, Log in or Sign up
e
  • ehot
  • March 31, 2024, 2:29 p.m.

C++ - Тест 003. Условия и циклы

  • Result:78points,
  • Rating points2
B

C++ - Test 002. Constants

  • Result:16points,
  • Rating points-10
B

C++ - Test 001. The first program and data types

  • Result:46points,
  • Rating points-6
Last comments
k
kmssrFeb. 8, 2024, 6:43 p.m.
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
EVA
EVADec. 25, 2023, 10:30 a.m.
Boost - static linking in CMake project under Windows Ошибка LNK1104 часто возникает, когда компоновщик не может найти или открыть файл библиотеки. В вашем случае, это файл libboost_locale-vc142-mt-gd-x64-1_74.lib из библиотеки Boost для C+…
J
JonnyJoDec. 25, 2023, 8:38 a.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
G
GvozdikDec. 18, 2023, 9:01 p.m.
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
a
a_vlasovApril 14, 2024, 6:41 a.m.
Мобильное приложение на C++Qt и бэкенд к нему на Django Rest Framework Евгений, добрый день! Такой вопрос. Верно ли следующее утверждение: Любое Android-приложение, написанное на Java/Kotlin чисто теоретически (пусть и с большими трудностями) можно написать и на C+…
Павел Дорофеев
Павел ДорофеевApril 14, 2024, 2:35 a.m.
QTableWidget с 2 заголовками Вот тут есть кастомный QTableView с многорядностью проект поддерживается, обращайтесь
f
fastrexApril 4, 2024, 4:47 a.m.
Вернуть старое поведение QComboBox, не менять индекс при resetModel Добрый день! У нас много проектов в которых используется QComboBox, в версии 5.5.1, когда модель испускает сигнал resetModel, currentIndex не менялся. В версии 5.15 при resetModel происходит try…
AC
Alexandru CodreanuJan. 19, 2024, 11:57 a.m.
QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…

Follow us in social networks