Define your own constant types in Objective-C

By | iOS, Mobile | No Comments

We are faced with the requirement of using enums frequently within our code but Objective-C Enums only allow for integer values, which don’t always fulfil our requirement. For example, if we need to store the state of a process as a string to later be sent on to a service.

Possible states:

Waiting

Running

Paused

Finished

 

If this were completed using enums, we would have something like this:

typedef enum {

Waiting,

Running,

Paused,

Finished

} ProcessState;

 

Imagine now trying to set a string value for your process property based on the enum. The result would be something like the following:

switch(state){

case Waiting:

<object>.processState = @”Waiting”;

break;

case Running:

<object>.processState = @”Running”;

break;

}

 

A more elegant solution would be to set these values directly, it’s more readable and plays nicely with auto complete. For that you need to do the following:

In your .h file:

typedef NSString ProcessState;

FOUNDATION_EXPORT ProcessState *const Waiting;

FOUNDATION_EXPORT ProcessState *const Running;

FOUNDATION_EXPORT ProcessState *const Paused;

FOUNDATION_EXPORT ProcessState *const Finished;

 

In your .m file:

ProcessState *const Waiting = @”Waiting”;

ProcessState *const Running = @”Running”;

ProcessState *const Paused = @”Paused”;

ProcessState *const Finished = @”Finished”;

 

Now just set values with:

<object>.processstate = Waiting;

 

Prefixes can enhance it further to work even better with code completion. So we can change the constant declarations to have a prefix before:

typedef NSString MPProcessState;

FOUNDATION_EXPORT MPProcessState *const Waiting;

FOUNDATION_EXPORT MPProcessState *const Running;

FOUNDATION_EXPORT MPProcessState *const Paused;

FOUNDATION_EXPORT MPProcessState *const Finished;

MPProcessState *const Waiting = @”Waiting”;

MPProcessState *const Running = @”Running”;

MPProcessState *const Paused = @”Paused”;

MPProcessState *const Finished = @”Finished”;

 

Now when we’re setting our process state property, we’re presented with a nicely human readable solution. That’s it!

OAuth

By | Android, iOS, Mobile, Windows | No Comments

OAuth has become a big technology in recent years, our App Experts are here to give you all the information you need to get started.

What is OAuth?

It’s a secure way to authenticate access to and share resources with third parties.

Example

Say we have a profile on a website x.com and we want to upload pictures from Facebook onto our x.com profile. Without OAuth, the flow would look something like this:

  1. From x.com we click on the ‘Upload pictures from Facebook’ button.
  2. While still on x.com, we’d have to input our Facebook Username and Password.
  3. We’re now able to select which images we want to upload.

In this scenario, we’ve passed our Facebook credentials over to an unverified third party (x.com) for handling. There’s no telling what this third party is doing with these credentials; they could be stored, distributed, or used; without our knowledge.

Now consider the same flow with OAuth:

  1. From x.com we click on the ‘Upload pictures from Facebook’ button.
  2. We get a popup from a verified facebook.com source asking for our Username and Password.
  3. We get another popup from a verified facebook.com source asking us to allow/disallow x.com to use our pictures.
  4. If we allow the service, we can now select the images we want to upload.

Now, in this improved scenario, we’re achieving the same goal, the sharing of images between Facebook and a third party, but without passing any, Facebook-based, secure or sensitive information to x.com (Facebook Password and Username). Our credentials are securely handled by the appropriate services throughout.

OAuth roles

With OAuth we follow the concept of decentralization of control; we have defined a set of roles, each of which will be fulfilled by different, specialized, servers. This improves security while still keeping an eye on efficiency.

The roles are:

Client –The entity requesting access to the resource housed on the resource server. (X.com)

Authorization server – A server, normally owned/operated by the same entity as the resource server, that will process and potentially authorize access to the resource server.

Resource owner – The entity that owns the requested data. (Our Facebook Profile)

Resource server – The server hosting the requested data. (Facebook’s hosting servers)

The way it works

There are 4 flows/grant types in OAuth 2:

Now for the flows

Authorization Code Grant
  1. Client sends a request to Resource Owner providing Client Id (x), Redirect Url (http://www.x.com), and scope (Photos).
  2. Resource Owner responds with an Authorization Code.
  3. Client then passes Authorization Code to the Authorization Server and receives Access Token.
  4. Client can now access the protected resource on the Resource Server with the Access Token.
Implicit Grant
  1. Client sends an authorization request to Resource Owner and gets the Access Token.
  2. Client can then use Access Token to access protected resources on the Resource Server.

This is basically the same as Authorization Code Grant, but the Resource Owner and Authorization Server roles are combined to one entity.

You may be, like I was, asking what’s the point of the Authorization Code Grant method if Implicit Grant is easier and uses the same principle. Basically, most people use Implicit Grant, but the Authorization Code Grant method provides an extra level of security and decentralization. Also, if we’re dealing with a large resource provider that has a lot of Authentication Servers, the Resource Owner server can send different Authentication Server urls depending on the load of particular authentication servers.

Resource Owner Password Credentials Grant
  1. Resource Owner provides his own credentials to the Client in order for the Client to access the protected resource.
  2. Client provides credentials to Authorization Server and gets an Access Token in response.
  3. Client can then use that Access Token to access protected resources on the Resource Server.
Client Credentials Grant
  1. Client provides credentials to Authorization Server and gets an Access Token in response.
  2. Client can then use that Access Token to access protected resources on the Resource Server.

Basically that was OAuth 2.0 simplified. Hope you enjoyed the read.

Reconciling iOS, Android & Windows Mobile Apps

By | Android, iOS, Mobile, Windows | No Comments

Android, iOS, and Windows mobile app developers alike are always on the lookout for the latest tools to simplify their workload, especially on multi-platform apps. Whether it’s a more organized way to produce code or creating a friendlier UI experience, our App Experts went on the hunt to look for possible solutions.

With the amount of training that developers go through to hone a native language, it’s dumbfounding to ask them to write code from another language. So, how can they transform their skills and transition seamlessly to another platform?

apple, android, windows, mobile

Our App Experts can code for any device.

The Popular Solution

Introducing PhoneGap, a developmental open source tool created by Nitobi. PhoneGap allows you to take your acquired knowledge from HTML, Javascript and CSS and use it to write for any mobile platform (iOS, Android, Windows). As a bonus, a developer can link your app to any of the main device features, such as a file system, camera, accelerometer or GPS. This allows your app to communicate effectively with the phone.

Alternative Solution

One of our App Experts also uses an open-source library called Scaloid, which enables Scala developers to create Android apps without migrating to Java. It uses many of Scala’s features including creating Domain Specific Languages (DSLs). The goal of Scaloid is to help reduce the cluster of codes as well as any type errors.

Scaloid Code

This example shows you how Scaloid reduces the amount of code that a developer needs to write.

Which Program Works Better?

Although developers can debate about which approach works better, most companies that want to create apps for all devices tend to lean towards PhoneGap. On the other hand, if a company is looking to break in to the Android market, then Scaloid may be the way to go.

What are your thoughts? Let us know below which open source tools you prefer to use and why.

Secure Sockets Layer Explained

By | Android, Glass, iOS, Mobile | No Comments

With all of the chatter about various ways to protect and encrypt our data from prying eyes, The App Experts mobile development team thought it was time to share some insight into SSL or Secure Sockets Layer and how it works to keep data protected during a transfer.

At its most basic level, SSL is a standard security technology leveraged by millions of websites globally. It is used to create a secure link between a web browser and a server, and it is designed to keep the data transmitted between the two private.ssl_logo

Before a secure connection can be established, however, the server requires an SSL Certificate. The certificate in created by answering a series of questions that will play a factorising role in creating two encrypted keys: a private key, and a public key.

The public key, doesn’t need to be secret, and can then be placed into a request known as a CSR, or a Certificate Signing Request for short. The CSR also contains relevant information about the user.

There is an application process for the SSL Certificate that requires validation by the Certification Authority that handles the validation of your details. Once validated, the SSL Certificate is issued aligning with the given details, and the user is able to use SSL.

When used, the webserver matches the SSL Certificate with the users’ Private Key, after which the users’ web browser will establish a secured and encrypted link between itself and website.

All of this happens more or less behind the scenes, which makes for a user friendly process. But for those who seek a little bit of a visual cue that all is secure, there can be found a small icon of a padlock in the web browser to let the user known that they are in safe, SSL standard, hands. Nice, no?

So what’s actually in the certificate, you may well ask? Usually it contains a domain name, company name, country, and expiration date of the Certificate itself, while information about the Certification Authority that issued the certificate is also held within.

After all, we want to know who, what, when, and how when it comes to securing us, right?

When a web browser contacts a web server, it checks the certificate expiration date, whether the certificate was issued by a known Certification Authority and it trusts, and whether the same certificate is being used by the website being accessed. Should any of these checks fail, then the user is informed via a warning before continuing to the web site. The user can still continue if they wish to take that risk, but they will do so knowing that the credentials didn’t match.

In closing, that’s pretty much how SSL works. So how about your experience? Is SSL enough security for you? How do you protect your data? Let us know in the comments section below. Cheers!

Gradle: Google’s New Android Build System

By | Android, Mobile | No Comments

If you talk to a typical Android developer about their choice in build tools, chances are you’ll overwhelming hear Maven. But there’s a new kid on the block looking to change that. android_gradleAccording to RebelLab’s recent global survey of 2164 Java professionals, Gradle ranked as the highest technology that developers are most interested in learning with 58%. Let’s take a look at what Gradle can do.

Google introduced Gradle as an advanced build system to create custom build logic through plugins. Google selected Gradle as the foundation of the Android SDK build system because it provides flexibility and imparts a common standard for the build system. With a declarative Domain Specific Language (DSL), Gradle developers have access to a single, authoritative build bath that powers both Android IDE and builds from the command-line.

The main functions behind Gradle is to:

  • Make it easy to reuse code and resources
  • Enhance the ability to make several versions of an application
  • Improve configuration
  • Good IDE integration

Features and Benefits of Using Gradle

  • Integration with Android Studio: Android Studio is tightly integrated with the Gradle build system.
  • Simple, Declarative, Domain-specific Language: Gradleware and Google works together to make simple, declarative DSL for Android builds.
  • A Single Build System: Gradle is the authoritative build across the IDE and command-line.
  • Product Flavours, Build Variants and Build Type: Provides an easy way to create keystore and signing configuration across different build type.
  • Dependency Management: Gradle offers a flexible dependency management that can use the existing Maven repositories or reference local JARs.
  • Multi-Project Support: Supports mutile project from both IDE and command-line.
  • Binary Bundles for Libraries (.aar): Gradle supports the new .aar binary bundle format for library projects.
  • Full Incremental Builds: Incremental Builds means your waiting time for build process will be reduced.
  • A Focus on Testing: With Gradle you can run unit and integration tests without creating subprojects. Gradle supports several scenarios for integration testing on build servers.
  • Test Server API supported Hosted Testing: Integration with Jenkins-based build servers and services from AppThwackTestDroid, and Manymo means that your build can support complex, massively-parallel integration testing scenarios.

Incorporating Gradle in Android Studio

Make sure you download the Android Support Repository under Extras using the SDK Manage

Gradle 1

The gradle.build provides some instruction on what you have to do.

Gradle 2

Gradle 3

Despite Maven dominating among Android build tools, fast-growing Gradle appears to be gaining in popularity among Android developers. Have you had the chance to experiment with Gradle? What are your thoughts on Gradle gaining momentum on Maven? Comment below!

 

Rumours swirl around Apple’s WWDC 2014

By | iOS, Mobile | No Comments

On Monday in San Francisco, Apple will be hosting its annual Worldwide Developer’s Conference.  While we’d love to make the trek to attend, we’ll have to make do with the streaming video of the WWDC.

While we expect that there will be some hardware announcements, we think that will be mostly on the iMac side of things, and probably not the time they’ll unveil a new iPhone or iPad model.  Instead, we think this will be when Apple will focus on the operating systems, and for us, we’re keen to see if there will be a reveal of iOS 8.

If you recall, it was last year at thejune_2014_posterframe WWDC that Apple announced iOS 7, which was a radical departure from the earlier iterations of the operating system.  We don’t anticipate such a game-changer as we had with iOS 7, but this might be when we see a decidedly new core function of the OS – fitness and wellness tracking.

9to5Mac.com has reported that Apple is  embracing this in a big way – with what is currently known as project code name Healthbook. 

Based on the images we’ve seen, the look and feel is similar to the current Passbook application.

Of course Apple may surprise us all with an announcement of a ‘phablet’ sized iPhone or a ‘pro’ version of a iPad – one can’t be certain with Apple, until the big keynote address. But based on past announcements, we expect this to lean heavily in the direction of the software, and not the hardware.

What do you think?  Will Apple put something out that we’ve never even considered?  Let us know in the comments section below.

How to Develop Hello World Google Glass Android App 

By | Android, Mobile | No Comments

Google Glass is an augmented reality wearable computer with a head-mounted display (HMD) that is being developed by Google in the Project Glass. It’s looking to reinvent the mobile device scene by providing hands-free Internet/computer access for users on the go. Despite this technology remaining in it’s infancy stage, our early adopter Google Glass App Experts have begun experimenting with the Glass Development Kit (GDK) so we’re thrilled by the potential this game changer has to offer. Below are some simple guidelines to follow to develop your first Google Glass app to leverage this emerging technology and familiarise yourself with the coding.

Developing A Google Glass App

If  you’re comfortable with Android, here’s all you need to know to get started:

  • Get the Android 4.4.2 (API 19) SDK and Glass Development Kit Preview add-on from the Android SDK Manager.
  • On Glass, turn on USB debugging (Settings > Device Info > Turn on debug).
  • Import some GDK samples with the File > New Project > Android Sample Project menu.
  • When you’re ready to create a project for your own Glassware, use these settings:
    • Minimum and Target SDK Versions: 19 (There is only one Glass version, so minimum and target SDK are the same)
    • Compile with: Glass Development Kit Developer Preview
    • Theme: None (ADT and Android Studio usually assign a theme automatically, even if you specify no theme, so remove the Android:theme property from your manifest after creating a project)
  • Don’t know where to start? Read these pattern and developer guides for additional information and helpful process tips.

Developing Hello World Immersion for Google Glass

This section describes how to create a simple hello world application for Google Glass using the GDK. There are two options for how the Glassware should show up on the device: as a live card that is part of the timeline or as an immersion that is displayed outside of the context of the timeline. We are focusing on how to write an immersion.

You might be wondering what is an immersion ? An immersion is basically an Android activity. The name immersion implies that it is not part of the normal Glass timeline. Instead, it takes full control of the device – except for the back gesture (Swipe down). To go back to the timeline you need to leave the immersion.

Google Glass 1

Project Set Up:

Create a normal Android project with the following settings:

  • Set minSDKversion and targetSDKversion to 15 (Android 4.0.3)
  • Set compileSDKversion to “Google Inc.:Glass Development Kit Sneak Peek:15”
  • Do not assign a theme to your application or derive your own theme from Theme.DeviceDefault.

Creating the Immersion:

Let’s create a simple activity. The Card class helps us to create a layout that looks like a timeline card.

Google Glass 2

Launching the Glassware Voice Commands:

After creating the activity, we need a way to start our Glassware. A common way to launch Glassware is to use a voice trigger. Let’s add a simple voice trigger to start our hello world activity.

First we need to declare a string resource for our voice command.

Google Glass 3

The next step is to create an XML resource file for the voice trigger using the previously created string value.

Google Glass 4

Now we can add an intent filter for the VOICE_TRIGGER action to our activity. A meta-data tag links it to the XML file we wrote above.

Google Glass 5

The developer guide requires you to add an icon for the touch menu to the activity (white in color on transparent background, 50×50 pixels)

An App Experts tip: the Glass Asset Studio is a helpful tool to generate these icons.

Google Glass 6

The Final Glassware

Now we can start our Glassware by saying “ok glass show hello world”:

Google Glass 7

Another option to start our Glassware is to use the touch menu and scroll to the “show hello world” command:

Google Glass 8

That’s it, you’re all set! We hope this tutorial has helped Android enthusiasts in developing their first Google Glass App. We look forward to seeing this new wearable experience takeoff. Stay posted for additional blogs on how to build great Glassware.

Have you had the chance to experiment with Google Glass? What are some of the major challenges you’ve experienced? Feel free to give us a shout below!

KitKat 4.4: Android’s Sweet Treat

By | Android, Mobile | No Comments

As of 2014, Google’s Android operating system powers more than One Billion mobile devices. Since carriers were free to use Android to power SmartPhones and Tablets, it wasn’t long before they offered Android-powered phones to their mobile customers for free – with a two year service plan, of course.

While their wide array of mobile devices and their unique customization capabilities make Android appealing for many users and developers, it makes for a decidedly fragmented market.  Getting updates and patches delivered and applied has been frustrating for both users and developers alike.

Resolving problems with fragmentation and performance as well as difficulties with seemingly simple tasks like applying updates have annoyed users and frustrated our Android Mobile App Experts equally.

To overcome this, Google launched their new OS Android 4.4 KitKat last November to take over the mobile world with some practical updates.

android-kitkat

 

 

 

What’s New

This newly updated version doesn’t offer a huge list of jaw dropping changes in functionality like the release of Ice Cream Sandwich, but where it lacks in bells and whistles, it makes up by offering more versatility for more devices. That is, this new version will be compatible with all Android devices from high-end to low-end, as long as as they run on 512 MB of RAM. This is an important advancement because there were phones that do not allow to upgrade the latest version of Android, which gave users an inconsistent experience. This forced some devices to run on older versions of Android with new applications on the market. Now with KitKat, Google’s expanded the operating system to run on many more devices, helping to bridge the gap between low-end and high-end devices alike.

Google’s Goal

Google is moving towards standardization with one target in mind — get KitKat on all Android devices, similar to how Apple has made iOS mandatory for it’s users. The reasoning is simple: fragmentation has plagued them far too long, making the cheapest devices nearly impossible to get the latest functionality without paying a high premium. Cheaper devices often have a smaller amount of memory storage and RAM, which meant that users could only run an old version of Android. Meanwhile, the more powerful and more expensive phones have faster processors and more RAM, allowing the latest version of the Google operating system.

How They Did It

Google reduced the size of the operating system by 16 percent, allowing it to run on devices with just 512 MB ​​of RAM, which meant that more affordable mobile devices could run the latest OS, which is exactly what Google is looking for. Google now offers the possibility of manufacturers to market their devices with the latest version of Android’s KitKat. In layman’s terms, more affordable choices + the latest in upgrades = global market domination. Pretty sweet idea, don’t you agree?

What do you think of Android’s 4.4 KitKat? Give us a shout below!

Android vs iPhone: Is marketing influencing mobile loyalty?

By | Android, iOS, Mobile | No Comments

Android or Apple? This debate is something that developers have been talking about for years and countless articles have argued the merits of one over the other. Our App Experts were discussing the two competitors recently, and an intriguing question came up to try and explain Apple’s success:  Can a good marketing strategy beat a cheaper product that’s similar in nature?

Apple completely changed the mobile world when they released the first iPhone. It was a remarkable moment. Blackberry was already in existence by that time, but Apple showed us that smartphones could be more than just a tool for work. They managed to expand from a phone previously used only for calling and texting to the preeminent key to unlocking the web on the go. Someone had to follow.

Android – The New Kids On The Block

When Android first appeared on the market, it was seen as a cheap alternative to having an iPhone. But Android grew in popularity thanks to having an open source policy which allowed developers to code freely. Today, Android captures the spirit of individuality and nonconformity. If you compare Apple’s iOS 7 with Android 4.4 (Kit Kat), you can see huge differences among them, but many functionalities mirror one another. So one has to wonder, if there’s such a massive gap in pricing, surely iPhones must deliver additional features? The answer is a resounding no. 

In fact, Apple is copying some things from Android. The new Apple iOS recently added some features that were around in Android for a long time, like disabling WiFi from the notification screen or the new task manager which is just an Apple version of the existing one in Android. 

Additionally, iOS 7 becomes problematic when you are using an old iPhone, like iPhone 4. Battery life lasts for a shorter time and some features are not available because the hardware is not ready for them. Some would argue this is a way to force people to buy a new phone every two years in order to be able to use the latest features.

So what about Android? They’ve added some interesting features like the new interface with a design that’s very clean and simple. They’ve incorporated some components from the flat iOS design, but it shows the elements in a clear way — not to mention the colour palette is appropriate for a device that the user is going to be looking at for a long period of time.

The question Android fans are puzzled with is why anyone would pay £500 for an iPhone when they can have a Samsung or a Motorola phone which provides the exact same functions for less than half the price of an iPhone? Sure, Apple products are beautiful and easy to use. But at the end of the day, Android gives more freedom to the user with customization capabilities. We’re going to suggest one possible answer for many Apple aficionados is in a genius marketing strategy. 

Power of Brand Awareness

The cult-like following of Apple’s products may be attributed to the hype Apple is able to generate for its consumers year after year. Nobody is able to build buzz and speculation on upcoming products and announcements like Apple. Their brand following is built on creating the ultimate user experience — from the packaging, design, to the products themselves, Apple has capitalized on fans looking to have the latest in gadgets. Just one look at the massive queues outside an Apple store during a new product launch summarizes the incredible demand these products generate.

Having all of this in mind, one must wonder the powerful effects of successful marketing efforts.  If most people aren’t moved by features or specifications, some other channels must be contributing to user preferences. Sometimes, a name seals the deal and you can see that every day in the tube or on the bus.

In a city like London, iPhones and iPads are more widely seen than Android devices. Why? That answer will vary user to user, but there’s no denying Apple’s global brand awareness and more importantly, loyalty. After all, Apple’s cool and sleek designs outsells a product that works on par and is significantly cheaper, so there is a sense of established value with the Apple community. Wherever your personal preferences lay, the war between Apple and Android continues…

We want to know: which operating system do you prefer and why? Comment below and join the debate.

Native versus Cross-Platform Mobile Development

By | Android, iOS, Mobile | One Comment

Mobile app developers are always faced with one of the most challenging decisions when building an application: should I develop native or cross platform? While there are obvious pros and cons for using either approaches, a lot of the determining factors lay in the app’s purpose and audience. Let’s examine the difference between native development and cross-platform development and the tools/frameworks used for them.

Native Development:

Native is code compiled for the specific devices using fixed development languages.

  • For iOS,  Xcode is used as the development tool and Objective C as development language.
  • For Android, Eclipse or Android Studio is the development tool and Java as development language.

Cross-Platform Development:

In cross-platform development, code is used and compiled for multiple platforms. Usually, HTML/CSS and Javascript are used as development languages.  Some solutions will compile it into native code, but they are never truly native.

  • Example Solutions: RhoMobile, Appcelerator, PhoneGap, MoSync.

Why choose native?

  1.  Better Performance: When coding with the indented programming language, you have access to the full device APIs. Though cross-platform solutions offer native APIs to use, you will have to wait until it is released in order to use it. When it comes to animations and gestures, native code will be more polished and slicker than cross-platform solutions.
  2. Better Solutions: There are some cross-platform solutions that will compile code into the native language, but none of them compile it to completely native so it becomes very hard to do the custom changes for the specific platform for the developer.  In native, there are less serious limitations between creativity and platform capabilities, which provides a developer better solution.
  3. Better Support: Developers we work with often say that they like to work in native code because it is easier to get help. They can go online to forums like Stack Overflow and quickly get answers since there are so many more people writing native code.
  4. Better Deployments: Issues with deploying  cross-platform codes are more prevalent compared to the native deployments because of its built in packages. Additionally, applications tend to suffer from real performance pains during run time.

The Verdict

When using cross-platform solutions, fragmentation is a major concern developers must overcome. The notion of a one size fits all approach to building apps is not realistic.

What do you think?  Let us know in the comments section below.