Image of Cordova and Angular logos displaying how to build a hybrid app using Cordova and Angular app using

Building a Hybrid App using Cordova and Angular in 2022

So the first time I wrote a hybrid app in Cordova was around five years ago when I was working writing a prototype for a start up Social Network. The prototype failed due to the instability of our Vanilla JavaScript front-end. This really goes to show how important it is to have a solid front end framework.

Luckily, I was blessed with the information that you could convert your Angular app into a fully functional and native capable hybrid app. And so in this article, we’ll be going over on how to convert your angular app into a cordova hybrid app.

Like I mentioned, after finishing a failed prototype with Vanilla JS, it was then that I learned about how you could use a JavaScript framework instead such as Angular to write your own hybrid app… to many web developers, this is a very comforting, comforting thought.

Now, I can write a whole app with native functionality using the Cordova Framework & Angular and it will run on three platforms (iOS, Android, and Browsers). In order to make this happen, you will have to learn how to use Cordova, a simple, lightweight, f***ing out of control, monster of a framework which has access to every single native function on your device, whether it’s an iOS or Android.

Coming from writing hybrid apps in Vanilla JavaScript, I was very happy to know how much easier things would get once I learned how to render my Angular app correctly using Cordova. And so after many attempts and I mean many attempts; I was successful. Walla! SpotBie! A fully functional app published on the web, iOS, and Android:

iOS
https://apps.apple.com/us/app/spotbie/id1439327004?platform=iphone

Android
https://play.google.com/store/apps/details?id=com.exentriks.spotmee.spotmee&hl=en_US&gl=US

This tutorial uses the following framework versions:

Android:

The biggest problem on this task (rendering the angular app correctly through Cordova on iOS and Android) was finding one big solid document detailing every single step of the process.

And so… here we go!

A you ready to unleash the full power of Cordova? When you use a Framework such as Angular, you become accustomed to quality. Being able to transfer this quality into a mobile app and being able to keep the same code-base for all three apps is incredibly useful.

You will only need to worry about learning two or three frameworks (if you include the back-end) if you choose this path. You will become an expert, and exploit every greatness and weakness that this workflow has to offer.

Don’t get me wrong, like with everything else, there are pros and cons to using this workflow. For me, it has been incredibly robust, loyal (seriously, I even have access to Apple Pay), and easy to work with. There are really a couple of setbacks I can think of when using this set up, I will go over them later throughout this blog.

On a brighter note, keep reading to find out more about how I achieved to release SpotBie using Cordova & Angular!

Writing a Hybrid App with Cordova & Angular; What you should know!

Image of Cordova and Angular logos displaying how building a hybrid app using cordova and angular in 2022

Creating your first hybrid app using cordova starts here. You will need to understand how Cordova works before jumping into this tutorial.

Additionally, if you haven’t already, give the Angular Framework a try or there will be no way you could build an Angular App. Duh. You can read more about it on their website here.

Onto the good stuff.

Converting your Angular app into a Cordova Hybrid App

This is where things get messy. But hey, as long as you love what you do, you will be fine.

We will cover the following steps which will get your hybrid app up and running:

  1. Setting up base href in your Angular App correctly.
  2. Adding build scripts into your package.json to trans-compile the app into JavaScript.
  3. Adding the onDeviceReady function to your main.ts file to bootstrap your app module.
  4. Adding missing Cordova dependencies to access native device functionality.
  5. Bridging the gap between Angular and Cordova.
  6. Building your Cordova app for production in iOS & Android.

1. Setting up base href in your Angular App correctly.

Android

In order to do this, you will have to open your index.prod.html file and add the following lines of code which will aide Cordova in understanding where your base href ( your base url for the application – such as https://example.com/ ). In this case our base href will need to change because our files are going to be read from a different directory since we are going to be using the file-system cordova builds for us instead of the default Angular base path.

Code to add into your index.prod.html file.

<base href="/">
<script>document.write('<base href="' + document.location + '" />');</script>
<script src="cordova.js"></script>
<script>        
  document.addEventListener("deviceready", onDeviceReady, false);    
  function onDeviceReady() { 
    window.open = cordova.InAppBrowser.open
   }
</script>

iOS

I had trouble getting this work on iOS because the procedure was not the same as for Android. The project would build but the main index file would not load and I would get this error instead in the safari technology preview console:

“/index.html” not found.

Here’s what you should add into your index.prod.html file’s head section in order for Cordova to fire up your Angular project:

<script>document.write('<base href="' + document.location + '" />');</script>

<script src="cordova.js"></script>

Notice how the base href is written differently by using the document.write JavaScript function instead.

Setting Up your App.

Additionally, you have to add this into your main.ts file.

The first thing you will need to do is get the Cordova framework installed on your development machine.

You will need to run the following commands in your favorite cli interface:

  • On Linux and macOS
sudo npm install -g cordova

Then, after installing Cordova, please go ahead and move into your source code’s directory and create the app using the following command:

cordova create hello com.example.hello HelloWorld

Wallah! Your Cordova project is ready for launch! Once you make sure that you provision the right certificates for your app developer profile, you will be able to launch the app with a few commands or through an IDE like XCode for OS X.

cordova create hello com.example.hello HelloWorld

This tutorial is not really dedicated to how to set up your Cordova app so if you want to learn how to do that please read the Cordova documentation.

2. Adding build scripts into your package.json to trans-compile the app into JavaScript.

In order to build your Angular app into the Cordova app you will need to add the following script under your “scripts: { ” section in your package.json file:

"build:android": "ng build --prod --base-href . --output-path /home/spotbie/Desktop/immigration-visa-attorney/www/"

"build:ios": "ng build --prod --base-href . --output-path ~/Desktop/spotbie/immigration-visa-attorney/www/"

Essentially what these scripts do is allow you to build into cordova’s www directory. After running “npm run build:android” or “npm run build:ios” your project will get rendered into their respective folders.

Now when you launch the project using Cordova you will notice that the first page that should be loaded is your Angular project’s home page.

3. Adding the onDeviceReady function to your main.ts file to bootstrap your app module.

Just like we did before, you also want to add the following code to your Angular main.ts file.

//For Cordova Functionality
let onDeviceReady = () => {
  platformBrowserDynamic().bootstrapModule(AppModule);
};
document.addEventListener('deviceready', onDeviceReady, false);

So with all that being said, the procedure is the same for both iOS and Android. This function simply bootstraps your AppModule into the browser platform for rendering.

4. Adding missing Cordova dependencies to access native device functionality.

Next up you will want to add all your cordova plugin dependencies starting with the platforms you are building for.

To add the Android or iOS platforms from within your cli type the following commands:

cordova platform add ios
cordova platform add android

I should mention that if you are trying to develop an iOS app it should be from your OS X computer.

To install the plugins you are missing you will need to cd into that platform’s directory and type the following command:

cordova plugin add <plugin name>

This will give you a list of all the plugins you have installed in your cordova project.

5. Bridging the Gap between Angular and Cordova.

BUT HOW??!?!?!? How is it possible to bridge the gap between front-end JavaScript functions and your devices native functionalities. Well, like the song says, “it’s easy once you know how it’s done.” But let’s get serious, how many of you are actually wondering WTF is going on here?

Well it’s actually quite straight forward:

Your Angular application will call functions using component local delegate functions which will invoke the global JavaScript version of the function which in turn has access to the global cordova object! Double Whammy! Guess what, your cordova app is now accessible through your Angular methods.

The magic does not stop there, you can clearly see how many different paths this can lead you down on, the possibilities are end-less.

FOR EXAMPLE: This is something I did to edit the swift file for one of the Cordova plugins we were working on:

Problem: I needed a Cordova plugin which would prompt the Camera permission app as soon as the camera was needed.

Plugins such as https://github.com/Cordobo/cordova-plugin-ios-camera-permissions were only helping add the needed permissions to info.plist which is where you should add all your string messages to be displayed on your app.

So here what ended up happening. The reason WHY I needed the camera was to add a QR Scanner which needs camera permission to be used. The problem was that the QR scanner had to be invoked using Angular through a JS delegator.

The first challenge in doing this however is that I could not possibly use this plugin: https://github.com/bitpay/cordova-plugin-qrscanner because it was outdated for iOS 8.0 as you can see in these screen shots:

Image of me building a hybrid app using cordova and angular.
Image of me creating a hybrid app using the cordova framework.

So in order to fix this, I had to edit the openSettings Swift method that came with the plugin.

As you can see the error came from these lines:

Image of me updating a qr scanner cordova plugin.

So that fixed that problem. I was able to compile the app successfully after doing so and move on to the next problem which is how would I be able to move to asking for the native device camera’s permission when the user opened the QR code scanner component within the SpotBie app.

Are Social Network Sites Good For Our Society?

Are Social Network Sites Good For Our Society?

You might be thinking that this article will be biased, after all this is a social networking site. However this article takes a different approach on answering a question that is important in today’s world: ‘are social network sites good for our society?’ In short, we will take a good look at the pros and cons that we found across the internet, see which ones are reasonable and which are not, then formulate our own opinion on the matter.

Are Social Network Sites Good For Our Society?

You might be thinking that this article will be biased, after all this is a social networking site. However this article takes a different approach on answering a question that is important in today’s world: ‘are social network sites good for our society?’ In short, we will take a good look at the pros and cons that we found across the internet, see which ones are reasonable and which are not, then formulate our own opinion on the matter.

First I would like you to keep in mind how many people are using social media today. According to the research article “The Rise of Social Media” conducted by the team at Our World in Data Facebook boasts around 2.4 billion users. To put this into perspective, the world population is 7.7 billion. It’s important to find out the answer to “are social network sites good for our society” That’s around a third of the world’s population that owns a Facebook account. This is only Facebook. What about YouTube, Twitter, Whatsapp, Instagram and the whole other myriad of social networks out there? Here, let’s take a look at this well put-together chart by the guys at Our World in Data which uses data from Statista

Image of Total Social Network Users across different platforms - from are social network sites good for our society?

So now let’s get to the issue at hand : are social media network sites good for our society? To answer this question, I have compiled a list of pros and cons taken from various different sources found on Google. I go a little bit into depth as to why the articles listed these pros and cons. Then I proceed with my own opinion derived from personal experience on each of these.

5 PROS of Social Networking Sites:

A Sense of Community: 6 years ago Ken Mueller posted an articles titled “11 reasons why people love and use social media”. Reason number one in that article is that people desire community. The article talks about how humans tend to ‘join groups and organizations’. The cool thing this article brings up is that through social media we can be parts of different communities disregarding location, time, and space.

I find this accurate. It’s in my personal experience that being part of a community is rewarding and alleviating in different ways. For example, Stackoverflow is “an open community for anyone that codes”. The community rewards its users who help other users answer any questions that have to do with coding such as bugs, syntax errors, or general how-to-s. It does really give you a sense of what a community should be like : helping each other grow by answering questions you know answers to. This particular ‘social network’ has helped me immensely in solving coding related problems, but I can think of other communities which have also helped me to be entertained and reach to people that I know and don’t know. It is a rational PRO of a social network site? Yes I do. Social media helps us grow various senses of community.

            Do you agree with this? From personal experience I can tell you that I enjoy being around people. There are also times however that I do desire ‘alone’ time, just like the article mentions. For one, I find it hard to be around people when they want to get personal all the times. These are the times when I like to step back and say it’s ‘me’ time, disconnect from all my social media, and look within. It’s very easy to accomplish this with social media however, all you have to do is log off!

Become more informed on current affairs: This point I found in an article which focuses on “The Pros and Cons of Teens on Social Media” While the name suggests these pros and cons would only apply to teens, it’s also arguable that they would apply to everyone else. While your Facebook and Instagram feeds are not the most reliable source of information, it can be said they are certainly a way for all of us to stay up to date. For the most part, this live stream of updates we receive from our friends and sometimes random people are very helpful. For example, if you were to follow CNN on Instagram, or let’s say NASA… you know you won’t be receiving bologna from such sources.


 On the other hand however, one might argue that the amount of fake news on social media is outstanding. This is why my opinion on this one is slighted towards “it all depends who’s the user”. If the user knows where to get reliable news from, then this is definitely an advantage to using social media. Another reason why I have decided to leave it in the Pros list is because ‘current affairs’ could also be referencing current affairs within your social circle where people are less likely to spread ‘fake news’.

Make New Friends: Using Social Media can lead to an decrease in loneliness. Research paper by Shelia R Cotten, PhD from University of Alabama at Birmingham suggests that “Using the internet may be beneficial for decreasing loneliness and increasing social contact among older adults…” While this research shows this to be true for the elderly, I also find it to be true for myself. As 27 year old adult, I find that a lot of interesting connections can be made through Instagram. I see it as a gateway to easily reach out to anyone I want with the tap of a few buttons. Something I would not be able to do otherwise.

Reaching Large Audiences: More than two thirds of Americans have social media profiles. This means that the Audience Reach you have in social media is huge if you know how to build it. For example let’s take a look at this infographic describing the number of U.S. Adults that use social media sites online or mobile:

The ability to reach such audiences gives your business or personal life a boost of excitement. Like we were saying before, meeting new people has never been this easy. By conducting research you could reach the audiences you wish through following graphs like the one above. Maybe people will start including their businesses when answering the question “Are social network sites good for our society?”

Allows You to keep in touch with people: While reading the article by Shelia R Cotten, PhD, from University of Alabama at Birmingham, one can draw the conclusion that Social media sites allow you to easil y keep in touch with people. Shelia R Cotton writes “Internet use enables older adults to stay in contact with others [20,21] and communicate with their social ties [22,23]. For example, email is more effective than in-person or phone communication for facilitating regular contact with family and friendship networks [2429]”.

Let’s think back to the days when webcam chats were not possible. It was an absolute hassle to get in touch with people that you wanted, especially when they were mile away. Nowadays, all you have to do is click a button and you’d be on your way to instant communication with whoever is in your social circle. There are things that we will forever owe to social media, and I think this is definitely one of them. The ease at which contact comes in this generation is something that never has been seen before and we should really appreciate it.

CONS of Social Networking Sites:

Lacks Emotion: In this article titled “Disadvantages of Social Networking : Surprising Insights from Teens” written by Marilyn Price-Mitchell, PhD we find some reasons why social networking can have a negative impact on society. One of these reasons is that social Media lacks emotion. Some people have a harder time sharing and expressing their emotions through social media. That is not the case with me in particular. On the other hand, I can definitely see how some people do lack emotion in the platform.

Easier for People to be hurtful: There are many ways in which social media can be hurtful. It is truly easier to be hurtful to someone through an online platform. This article written by Marilyn Price-Mitchell, PhD gives various insights from teens about the negative impact of social media. Reportedly one teen states “Honestly, I sometimes truly wish that ‘tools’ such as the iPhone (or any smartphone), laptops, iPads, tablets, etc. hadn’t been invented. Sure, they’re great, incredibly useful, and fun time-killers. But the way teenagers abuse them, and turn them into mini social control rooms is frankly awful.” When asked “How has online social networking influenced your relationships with friends and family?”, that’s what the boy responded. Marilyn Price-Mitchell, PhD goes to write about the disadvantages of social media according to essays written by tenth graders. Let’s see what the disadvantages listed were:

  1. Lacks Emotional Connection
  2. Gives people License to be hurtful
  3. Decrease Face-to-Face communication Skills
  4. Conveys Inauthentic Expression of Feeling
  5. Diminishes Understanding and Thoughtfulness

There are more reasons listed by these awesome tenth graders and if you want to read them please give the article about “Disadvantages of Social Networking” a visit.

Personally, I think that these teens are correct about some of the disadvantages that they have listed. These are disadvantages that SpotBie – The new Social Network will work to improve. HOWEVER, I also feel that tenth grade teenagers are not the right demographic for social networks. Social networks are to be used by mature teens, around the age of 18 or more. According to this article about ages required to make social media accounts users have to be only 13 years old to use some of these social media networks. I think this age requirement is morally incorrect for many reasons but I will I go into depth for that in my next article. One thing I agree with however is that people do tend to be more hurtful on social media; since it’s easier to not take responsibility for one’s words and not deal with their consequences. If you or anyone you know is a victim of negative hurtful social media comments I suggest you take a look at this article

A perfect example of how people can be hurtful on Social Media can be seen here in this video by renowned YouTube Host Philip DeFranco; idk man its the news. I’m exhausted.😤 Florence Pugh, Zoom Bans, “Hopeful” Coronavirus Update. It’s crazy how much easier it is for people to direct their towards somebody online.

Privacy Issues: One of the biggest privacy issues of social media is that you are exposing yourself to the whole world if you are not careful. For example, you might have a public profile in which everyone is allowed to see your content even if they are not in your social media circle or ‘friend’s list’. This article found on LifeWire mentions three privacy issues in social media:

  1. Social media sites own your content after it’s posted
  2. Becoming a target after sharing your location online
  3. Getting in trouble at work after posting something inappropriate.

These are all problems that SpotBie – The New Social Network is fighting to address. For example our long distance location sharing is allowed only after pairing with someone privately, and when you are not paired, you can only see people in a small radius instead of being able to see anybody’s location at anytime.

Distraction: The LifeWire article also talks about how Social Media Networks can be a distraction. This is something I can attest to because I myself struggle with being distracted by social media. However I don’t think it’s fair to blame the networks themselves just because people can’t control their actions. The articles states that Social Media is responsible for someone constantly looking at their phone, even to the point to cause distracting driving. SpotBie – The New Social Network will try the best in order to keep people from using social media more than they wish to. SpotBie will let users know how much time they have spent online per day, week, month, and year. Hopefully this method will rise the awareness of using social media too much. SpotBie is always trying for the answer “Are Social Network Sites Good for our Society?” to be a positive answer!

False Information: This article written by Soroush Vosoughi, Deb Roy, and Sinan Aral researches “The Spread of true and false news online” The authors have analyzed online stories from Twitter and reached the following conclusion “About 126,000 rumors were spread by ∼3 million people. False news reached more people than the truth; the top 1% of false news cascades diffused to between 1000 and 100,000 people, whereas the truth rarely diffused to more than 1000 people.” That’s a lot of fake news. The question is how do you battle fake news? In order to do so, SpotBie Accounts will be warned to the point of permanent bans after one of our content curators declares their articles as false. This puts SpotBie in a unique position of arbitration, but to help verify the news as true or false, we will reach out to other networks and sources. Also SpotBie accounts that post news must set their account category as “News Blog/Feed” if they do not want to be banned from the platform. This will help us identify which accounts are providing news and ban those who are doing so in order to spread false ones.

I hope you enjoyed this article and that you can begin to see why SpotBie is reaching to be the best and first Social Media Platform in the industry. We keep users first and always will. So hopefully the next time you think about the question ‘are social network sites good for our society?’ you will think about SpotBie! We find the problems that other Social Media platforms have brought to our society and help to solve them. We also reach to bring innovative new features that will keep the industry relevant and interesting. If you have any good things to say or complaints about Social Media what would they be? Share them with us below. Let’s create a solution for these problems! Please leave comment below by answering the question “are social network sites good for our society?”

Want to read more of our blogs? Click here.