Qt for iOS introduction wanted
-
wrote on 14 Aug 2021, 13:13 last edited by
Looking for a guide explaining how Qt can interact with iOS. Similar to what is available for Android. There are notification examples for Android, but cannot seem to find anything like that for iOS.
I have a project which is fetching data from a server every 10 seconds. This works fine in Android, since I have written an Android Service taking care of the data polling in the background, feeding the data to Qt through JNI.
However, how is the same procedure done for iOS? How do I interact with Qt from iOS, and from Qt to iOS?
I need to be able to send data to/from Qt and to/from iOS.
Any guide available?
-
Hi,
AFAIK, there's no direct equivalent to Androïd service.
See here for some information about background activities on iOS.
-
Hi,
AFAIK, there's no direct equivalent to Androïd service.
See here for some information about background activities on iOS.
-
The official language is Objective-C/C++.
However, it might not be mandatory to use 100% native APIs depending on what you do.
-
wrote on 15 Aug 2021, 23:10 last edited by
I have a very small public example of mixing Objective-C++ (an
mm
file) into a Qt5 iOS mobile app.This might be helpful just in terms of the basic mechanics of adding
*.mm
files (Objective C++) to your project.However, I never did anything as complex as a background "service" (or whatever such a thing should be properly called on iOS).
-
The official language is Objective-C/C++.
However, it might not be mandatory to use 100% native APIs depending on what you do.
wrote on 16 Aug 2021, 00:02 last edited by@SGaist Okey...
I'm looking for a guide explaining how one can pass data from native iOS to the Qt part.
My app will fetch data in the background every 10 seconds. This data need to be passed to the Qt part whenever data is recevied, for the UI to be updated accordingly when app is opened.
Also the background "service" in iOS (don't know what the equivalent is in iOS for background service in Android) needs to be able to send a local notification to the user.
Mainly what I do is to fetch data from a server every 10 seconds. Whenever there's a reason to notify the user regarding the data received, a local notification is sent to alert the user something changed.
What I'm missing is knowledge regarding how to pass data from native iOS to Qt. Similar to what can be done with JNI for Android.
Do you guys know how to achieve that?
Also, I need to declare my iOS app to run in the background, since I need to poll data from the server every 10 seconds. How do I do that? For Android it is declaring the app as a foreground service.
Thanks!
-
There's an article linked in the thread I suggested above that gives more details about the various modes and how to use them.
As for transferring data, you might be able to leverage directly Qt to load the data from your sever.
Otherwise you have to explain what data do you fetch from your server. There are already quite a lot of type conversion helper in Qt between native macOS and Qt types.
-
There's an article linked in the thread I suggested above that gives more details about the various modes and how to use them.
As for transferring data, you might be able to leverage directly Qt to load the data from your sever.
Otherwise you have to explain what data do you fetch from your server. There are already quite a lot of type conversion helper in Qt between native macOS and Qt types.
wrote on 16 Aug 2021, 20:58 last edited by@SGaist
Hello!Yes, I start to realize there are big differences between Android and iOS.
My intention it to pull JSON data from a server every 10 seconds. I have found ways of forcing the app to operate in the background using the Background Modes available in Xcode.
My next issue is regarding mixing .mm files with my .cpp files.
I need to send local notifications to the user from the app, when the app is in background mode. That's why I'm looking for info regarding passing data between iOS and Qt.
That is, the app will send local notifications to the user (not pushed from a server) to notify him/her that something changed in the data received.
For that, I would need to trigger a local notification to be shown, meaning my Qt code needs to trigger some iOS specific notification handler to show a notification. That trigger I do not understand how to perform.
Does that explain my problem?
-
You can check the sources of the QtMacExtras module to see how you can use Objective-C++.
iOS has local notifications for your needs.
One thing you don't explain is how you are retrieving data. As said before you might be able to leverage QNetworkAccessManager and thus do no need any type conversion. Or just pass the json as string and do the processing in the full Qt part of your application.
-
You can check the sources of the QtMacExtras module to see how you can use Objective-C++.
iOS has local notifications for your needs.
One thing you don't explain is how you are retrieving data. As said before you might be able to leverage QNetworkAccessManager and thus do no need any type conversion. Or just pass the json as string and do the processing in the full Qt part of your application.
wrote on 18 Aug 2021, 10:46 last edited by@SGaist
Thank you! I think I solved it thinking a bit about it. I can use QNetworkAccessManager, since iOS will define the process using Background Modes.Now I'm facing a bit more hidden issue.
I've declared my app using the correct Background Mode. It works smoothly and correctly in simulation. The app fetches data every 10 seconds, and displays a test notification, in active mode, in background, and when phone is locked. It all works.
However, when downloading the app to a target phone, background running is disabled as soon as the app is no longer in active state.
I've looked at Info.plist and copied and replaced the one being built with a copied version + the added background modes. It still does not work.
I've not been able to find any info if the Info.plist is my issue or not, but since it's working fine in simulation, my guess is that Info.plist is the problem.
NOTE: I've enabled all background modes in Xcode just to be sure. In simulation it works, but not on target.
1/10