Mobile App using JavaScript / Angular

How to create awesome mobile applications using Javascript? I have an answer — Cordova. A lot has already been written about hybrid and native applications, and their advantages and disadvantages. Including a lot written about Cordova. But over time, everything changes and those features and methods that worked before are not available now. Therefore, today I want to pay attention to the actual features of developing a mobile application for iOS using Cordova!
Purpose: To transfer the finished application on Angular to a mobile application.
Minimal required stack:
1. Angular app
2. Backend app(nodejs, express)
2. Cordova app
3. Xcode
How to install Cordova, create Angular and Cordova apps are described in detail in the corresponding documentation (for Angular / for Cordova), so we will not waste time on this, and we will immediately move on to important practical features that almost no one talks about.
Actions in the Angular app:
1. Build your app and look at “dist” directory.
ng build --configuration production
2. rename “dist” to “www”.
3. copy “www” directory.
Actions in the Cordova app:
1. replace “www” directory with copied.
2. cordova platform add ios
3. add cordova plugins:
- cordova plugins add cordova-plugin-device
- cordova plugins add cordova-plugin-ionic-webview
- cordova plugins add cordova-plugin-splashscreen
- cordova plugins add cordova-plugin-statusbar
4. cordova build ios (to compile code from “www” to “platforms/ios”)
Actions in the Xcode:
Then you need open Xcode and run files from “platforms/ios”. Don’t worry if it doesn’t start right away. If you are new to Xcode you need to set it first (create apple developer account, sign your app etc.).
After that you can open Cordova app in the simulator or your device.
Actions in the backend app:
The next thing you might encounter is Cross-Origin Resource Sharing (CORS).
Cross-Origin Resource Sharing (CORS) is an HTTP-header based mechanism that allows a server to indicate any origins (domain, scheme, or port) other than its own from which a browser should permit loading resources. CORS also relies on a mechanism by which browsers make a “preflight” request to the server hosting the cross-origin resource, in order to check that the server will permit the actual request. In that preflight, the browser sends headers that indicate the HTTP method and headers that will be used in the actual request.
It solved by adding to your backend this code:
let allowedOrigins = ["ionic://your_domain", "app://your_domain"];
Your created iOS app isn’t support http/https protocols and uses “ionic” or “app”.
Actions in config.xml:
Cordova app contains file config.xml for more detailed configuration (app icon, splashscreen, statusbar etc.). But even here there are some nuances that you should pay attention to.
1. For connect your backed and frontend you need to add:
<preference name=”hostname” value=”your_production_domain” />
2. splashcreen (it takes only center of your image)
3. app icon (need to add all types of icon)
4. from Iphone 11 you need padding top of “body”
5. After all changes in config.xml you need to run command — “cordova build ios” and rebuild it in Xcode again.
I attached my example of config.xml because it is very important part.
<?xml version='1.0' encoding='utf-8'?>
<widget id="your_id" version="1.0.0">
<name>Name</name>
<description>description</description>
<author email="author">
author
</author>
<content src="index.html" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<preference name="scheme" value="app" />
<preference name="hostname" value="your_domain" />
<preference name="ScrollEnabled" value="true" />
<platform name="ios">
<splash src="res/screen/ios/Default@3x~universal~anyany.png" />
<icon src="res/ios/icon-60@3x.png" width="180" height="180" />
<!-- iOS 7.0+ -->
<!-- iPhone / iPod Touch -->
<icon src="res/ios/icon-60.png" width="60" height="60" />
<icon src="res/ios/icon-60@2x.png" width="120" height="120" />
<!-- iPad -->
<icon src="res/ios/icon-76.png" width="76" height="76" />
<icon src="res/ios/icon-76@2x.png" width="152" height="152" />
<!-- Spotlight Icon -->
<icon src="res/ios/icon-40.png" width="40" height="40" />
<icon src="res/ios/icon-40@2x.png" width="80" height="80" />
<!-- iOS 6.1 -->
<!-- iPhone / iPod Touch -->
<icon src="res/ios/icon.png" width="57" height="57" />
<icon src="res/ios/icon@2x.png" width="114" height="114" />
<!-- iPad -->
<icon src="res/ios/icon-72.png" width="72" height="72" />
<icon src="res/ios/icon-72@2x.png" width="144" height="144" />
<!-- iPad Pro -->
<icon src="res/ios/icon-167.png" width="167" height="167" />
<!-- iPhone Spotlight and Settings Icon -->
<icon src="res/ios/icon-small.png" width="29" height="29" />
<icon src="res/ios/icon-small@2x.png" width="58" height="58" />
<icon src="res/ios/icon-small@3x.png" width="87" height="87" />
<!-- iPad Spotlight and Settings Icon -->
<icon src="res/ios/icon-50.png" width="50" height="50" />
<icon src="res/ios/icon-50@2x.png" width="100" height="100" />
<!-- iTunes Marketing Image -->
<icon src="res/ios/icon-1024.png" width="1024" height="1024" />
</platform>
<preference name="SplashScreenDelay" value="3000" />
</widget>
I tried to describe all the features that I encountered when creating the iOS mobile application using Angular and Cordova. I think that it is really good opportunity to convert your web app into mobile app.