MASARYKOVA UNIVERZITA FAKULTA}w¡¢£¤¥¦§¨  INFORMATIKY !"#$%&'()+,-./012345

iOS application for sharing and managing contact information

BACHELORTHESIS

Radomír Vinkler

Brno, spring 2015 Declaration

Hereby I declare, that this paper is my original authorial work, which I have worked out by my own. All sources, references and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source.

Radomír Vinkler

Advisor: RNDr. Vojtˇech Rehák,ˇ Ph.D.

ii Acknowledgement

I would like to thank my advisor RNDr. Vojtˇech Rehák,ˇ Ph.D., for his help, valuable advice, comments and willingness during the prepa- ration and writing of this thesis. Furthermore I would like to thank my friend Michal Kaprál for his valuable ideas and support. Finally I want to thank my family for their support during my studies.

iii Abstract

The aim of this work was to create a mobile application for iOS that would allow the user to share his contact information with his friends and then get the same information from them. This data would be saved in an online database. Part of this work is also a brief descrip- tion of iOS operating system, description of BaaS services and anal- ysis, design and implementation of created application.

iv Keywords iOS, mobile application, Apple, BaaS, synchronization, Parse, back- end

v Contents

1 Introduction ...... 1 2 iOS ...... 2 2.1 History of iOS ...... 2 2.2 Development Tools ...... 4 2.3 Development Language ...... 4 2.4 Application distribution and publishing ...... 6 3 BAAS services ...... 8 3.1 Introduction to BaaS ...... 8 3.2 Top BaaS Providers ...... 10 3.3 Parse ...... 13 4 Application ...... 18 4.1 Existing solutions ...... 18 4.2 Analysis and Design ...... 20 4.3 Implementation ...... 22 4.4 Testing ...... 28 5 Conclusion ...... 30 A Application screenshots ...... 33

vi 1 Introduction

Smart devices are one of the characteristics of today’s world. In this modern world almost everyone possesses some sort of smart device, be it smart phone or a tablet. The rise of these devices goes hand in hand with the increasing importance of social networking. While social networks allows people to engage in social interactions while being online, the allow them to take their social net- works with them everywhere they go. This on the other hand has caused the creation of a number of different social networks. These networks can change very quickly, generating a need to update the information about your friend’s profiles often. It is almost impossible to keep up to date with all these changes.

The aim of this work is to create an application for that would satisfy this need. The application should run on the iOS oper- ating system and the development is aimed at releasing this applica- tion for public. The application should minimize the need to update the contact information for your friends by gathering all this infor- mation from the user and allowing his friends to view this informa- tion. This way the user only needs to update his contact information once for all his friends to see this update. The online database should be implemented using some type of BaaS1 service that will eliminate the need to create and maintain my own server.

This work is divided into three major parts. The second chapter discusses the iOS operating system from the point of view of ap- plication developer. The chapter is dedicated to description of different BaaS services, the basics behind this solution and the choice of service provider for my application. The last major part describes the actual implementation of my application and explains the design choices and important parts of my application.

1. Backend-as-a-Service

1 2 iOS

The aim of this chapter is to provide an overview of the iOS operating system and the ecosystem provided by Apple1. We cover the major changes that happened in the history of iOS and in the recent ver- sions. After that we move on to currently used tools in development of iOS applications and provide an overview of the language that is being used when developing these applications. The last part of this chapter is dedicated to the distribution of finished applications.

2.1 History of iOS iOS (or iPhone OS2) is a created by the com- pany Apple Inc. It is an operating system specifically designed for use in Apple products, such as iPhone, iPad or iPod, and is being used exclusively in these Apple devices, since Apple chose not to provide licensing to other device manufacturers.

iOS was revealed early in 2007 [6] and released later that year in June. The purpose of this new operating system was to create an ex- tension to an existing operating system Mac OS X, used in personal computers, that would support the new hardware (new generation of smartphones), while allowing existing developers to write soft- ware with minimal retraining, as described in [17]. The important milestone for software developers was in March 2008, when the offi- cial SDK3 was released and developers could start creating new ap- plications for new hardware that runs iOS.

2.1.1 Versions Since the release, there have been introduced 8 major iterations of the operating system. The major versions released annually (named iOS 6.0, 7.0, ..) always come with new hardware (new version of

1. Apple Inc., a US based company 2. Name iPhone OS was replaced with iOS 4 after release [16]. 3. Software Development Kit

2 2. IOS iPhone), and usually bring major updates in design, core applica- tions and frameworks4. Minor versions (called iOS 8.0, iOS 8.1, ..) usually bring smaller upgrades, redesigns or support for newly in- troduced hardware.

From the point of view of the developer, it is important to note that the new versions of iOS are able to run applications written for the former version, and that the hardware is generally supported for at least 4 years. This means that with the introduction of a new major version, the applications should be functioning properly with only small changes in code. New versions usually introduce new design patterns and functions, while still supporting the older ones.

The distribution of iOS versions is very uniform, since the updates are provided free of charge to most of the existing hardware. Ac- cording to the data retrieved from official Apple website [8] 82% of devices using the AppStore, an official application from Apple used to download other software, are running iOS 8. iOS 7 takes 17% share of the distribution, and only 2% of devices use older version. This means that developers have to support only the two latest versions in most cases.

Figure 2.1: iOS version distribution among devices, from [8]

4. Framework is a software structure that provides particular functionality to fa- cilitate the development.

3 2. IOS 2.2 Development Tools

There are not many options in what tools you can use when devel- oping for iOS. The basic requirement that you need to fulfill is to own a computer running Mac OS 10.9.4 or later, IDE5 and iOS SDK, as in [11]. Xcode is a program that can be downloaded via Mac AppStore and is free of charge. After installing Xcode on your Mac, you will get several tools that will help you with development of your applications. I’m listing the core tools that are essential and that I used during the development of my application.

The main part of Xcode is the editor, which is used when writing code, compiling, debugging and analyzing the application. It pro- vides error checking, documentation, warning and auto- completion, which all facilitate the coding part. The editor also has built-in , a tool that is used to create and design your application looks. Its most important feature is the display of storyboards, which provide you with an overview of all your ap- plication screens, and the flow of control between them. This brings us to iOS Simulator, which simulates the actual hardware (iPhone, iPad, ..) and provides us with means to test the functionality, and show the design of our application. The last featured tool is instru- ments, which allows us to analyze running applications and collect data about performance, memory usage or network connection. All this and more is described on the official Apple website [13].

2.3 Development Language

Application development for iOS is done using language called Objective-C. Objective-C is an extension to commonly used C pro- gramming language, allowing object-oriented programming and featuring Smalltalk-style messaging system. It was developed by Brad Cox and Tom Love [18] and is nowadays used in operating sys- tems Mac OS and iOS by Apple. Objective-C was developed as a strict superset of C language. This means that any code written in C

5. Integrated Development Environment

4 2. IOS

should run without issues when compiled using Objective-C com- piler. This is a big advantage for developers, because they can use any library written for C and use it in their code.

The source code files have similar structure to the one used in C. Every class has a header file with .h extension, and a matching im- plementation file with .m extension.

Messaging Messaging is the feature of Objective-C that is inherited from Smalltalk. The main difference from regular C is that in Objective-C we are not calling methods, but sending messages. The difference lies in the interpretation of the code, since messages are being resolved during runtime. This provides more flexibility to the programmer, but can also introduce more errors during runtime. The syntax for sending messages is [object method:argument];

Header file The header file usually contains the interface of the class. In the inter- face we have defined the class that we inherit from, protocols (com- monly called interface), as well as properties and methods. @interface classname : superclassname @property prop1_type prop1_name + classMethod1; − (return_type)instanceMethod: (param1_type)param1_varName; @end

Implementation file In the implementation file we implement the methods that were de- clared in the header file. We can also declare other private properties or methods. Implementation file usually contains multiple #import statements. The #import statement is similar to #include used in C,

5 2. IOS

although #import will make sure that each file is included only once per compilation. #import "classname.h" @implementation classname + (return_type)classMethod { // implementation } − (return_type)instanceMethod { // implementation } @end

Singleton There is also one specific programming pattern that is used com- monly in iOS development. It is called singleton pattern and it basi- cally restricts the instantiation of a class to one object. This pattern is used in classes that run in the background of the application and that are usually coordinating the behavior of the whole application. Although they are often considered a bad design [4] they are being used commonly in designing iOS applications even by Apple.

2.4 Application distribution and publishing

The last part of this chapter is dedicated to application distribution. All Apple devices come bundled with an application called App- Store that allows users to discover and download new applications. This provides the developers with an easy way to distribute their application to millions of customers [9] around the world.

2.4.1 Publication process In order to be eligible to publish your application on the AppStore, you need to be a member of iOS Developer Program. This mem- bership costs $99 per year and needs to be renewed every year, oth-

6 2. IOS erwise your application will be pulled off from the AppStore. The developer program provides the developers with the ability to test their application on real devices (impossible without the paid sub- scription), access to official developer forums on Apple website, and access to iTunes Connect.

iTunes Connect is the core tool used when testing and publishing your application. It is a suite of web-based tools [10] for managing content sold on the AppStore. After uploading your application from Xcode to iTunes Connect, you have total control over what will hap- pen with the version you just uploaded. You have the possibilities to test it with a limited number of users, set the monetization options for your application, setup In-App purchases and view analytics of how your application performs in the AppStore.

After uploading your application to iTunes Connect, the last step before it gets to the customers is to submit it for App Review. This is an important part of Apple philosophy, because it ensures that the published applications are reliable, perform as expected and are free of offensive material, as noted in [7]. This also ensures that the App- Store will not be overfull of copied and unoriginal applications. After your application was successfully approved by Apple it will be pub- lished on the AppStore and available for download to all users of iOS.

7 3 BAAS services

This chapter is focused on BaaS services. There is an introduction about what BaaS services are, why we use them and what we use them for. After the introduction section is a description of various different BaaS providers and what they offer for developers. In the last part of this chapter I am presenting my choice of BaaS provider, with explanation of why I chose this provider and how I use its ser- vices.

3.1 Introduction to BaaS

Backend as a service, also called mobile backend as a service (from its use in mobile development) is a raising trend in application de- velopment. Thanks to the boom of mobile devices a new market has emerged providing backend services to mobile developers. Back- end serves as a layer in application invisible to the user that pro- vides a database and services used with the database. BaaS provides the developer with means to connect your application to their back- end storage and servers while also providing extra features like user management, push notifications or social networking integration [1]. They bring a purely backend, already constructed infrastructure to developers in order to facilitate and speed up the development, as well as make it cheaper. The main advantage of BaaS services is that the cloud servers automatically scale and optimize to ensure maxi- mum efficiency while providing big flexibility in order to satisfy all customer needs.

Each provider provides the developer with custom made SDK of API1. The provided features differ with each provider, but usually there are a number of core functions that are common for all of them. These core features include user management used for registration and login, content management allowing the creation, management and deletion of content and data system providing the functions of a database, as described in [15]. Most important part of these is

1. Application Programming Interface

8 3. BAAS SERVICES database management which provides the developer with means to store and retrieve data from an online system. These core function- alities may differ slightly in their implementation, use of different frameworks or systems, and number of features provided. Many providers add more extra features, such as cloud code, monetization options or push notifications.

3.1.1 Advantages and Disadvantages There are certain advantages and disadvantages in using BaaS ser- vices in development of an application. I have compiled a list from an online source [1] describing major advantages of BaaS services: Efficiency Gains Development costs are reduced in all stages of de- velopment thus also increasing efficiency. Faster Development Reducing the obstacles and amount of code that needs to be done significantly reduces development time. Fewer Resources The number of developers needed is smaller as well as eliminated need for supporting equipment such as servers. Optimized System The services provided are usually very well op- timized for mobile devices in their use of network and power. Secure and Scalable Infrastructure Developers don’t need to deal with security and scale of the infrastructure needed for their application as it is scaled as needed. API Resources APIs by providers usually bring all common resour- ces and essential functions into a single stack, reducing the need to gather them separately. There are also few disadvantages to using BaaS services. They are listed here: General Solution BaaS is often useless when you need to have a special functionality or seek a solution to a unique problem. Pricing While the basic service is usually free, when dealing with big amount of traffic it can get very expensive.

9 3. BAAS SERVICES

No Control over Infrastructure You don’t have any control over the infrastructure and if the service is unavailable or crashes you can’t do anything about it.

Out of Business Your BaaS provider may go out of business, so it’s important to choose the right company with strong founda- tions.

3.1.2 Pricing

BaaS is a service that needs to be paid for since the providers need to pay for servers, support and development. There are many pos- sibilities to how they can charge you, however two basic options have come out as the most common. The most common approach to charging for these services is number of API calls. This usually characterizes how often users use these services in your application and the price for the use of them increases with the number of these calls. The other main method of generating revenue for providers is storage. The more storage space you need for your application, the more servers they need to reserve for you and the more they are go- ing to charge you. Often these two ways of pricing are combined together.

3.2 Top BaaS Providers

While I have listed the reasons why we use BaaS services, when we use them and their advantages and disadvantages, it was all a gen- eral information. Here I am presenting 5 major companies that pro- vide BaaS services to developers. All these companies are already well established in this business and all of them offer good services. All of them offer similar core functionality, such as online documen- tation, push notifications, user authentication APIs, and all of them support the two major platforms iOS and Android. The differences between these services is how they handle these features, which will be described in detail on the next lines.

10 3. BAAS SERVICES

AnyPresence

The main feature of AnyPresence2 is that it not only provides back- end services for the developer, but it also provides a way to build an entire application using its system. Using the AnyPresence on- line designer you are able to generate backend code, application code and also your own customized API code. This code is multiplatform, meaning that it can run on any platform. The AnyPresence designer generates the user interface for you and allows you to download the application code and design, so you can edit it and run on compat- ible platforms. It supports iOS as well as Android and many other smaller operating systems. The big downside of this solution is the pricing, since it is on an enterprise-level, meaning that the costs of this solution are huge. The other downside is that it doesn’t provide a monitoring system used for analyzing your application.

Appcelerator

This company’s3 flagship offering is the Appcelerator Titanium, a lo- cal development environment capable to compile JavaScript code to native code that can run on iOS, Android or a different device. It also provides APIs for developers to implement Appcelerator back- end in their own applications. A big part of Appcelerator service is the analytics. You as a developer can see an overview of application installs, sessions, API calls or crashes right on the overview page of Appcelerator dashboard. You can also measure performance using performance metrics and manage the database directly online. The downside of Appcelerator is that it doesn’t offer even basic free ser- vice, and that the online documentation lacks certain features. The pricing is acceptable starting at $39 per month, while also offering premium enterprise solutions.

2. http://www.anypresence.com/ 3. http://www.appcelerator.com/

11 3. BAAS SERVICES

FeedHenry FeedHenry4 is an enterprise oriented service which is based on Node.js, an open-source runtime environment for server and net- working applications written in JavaScript. It features both online and offline development and supports collaborative application building with integration of GitHub5. It natively supports SDKs for iOS, Android and Windows Phone as well as hybrid applications based on HTML5 or Appcelerator Titanium. The downside is that it only supports Node.js development, and that it is enterprise-level priced, starting at $1500 per month.

Kinvey Kinvey6 is one of the more typical BaaS providers, as it aims for good backend support, integration of different databases and pro- vides typical functions as data store, push notifications or analytics. It also allows to run custom code online in the cloud. Kinvey is not addressing developers with one huge application, but to rather fo- cuses on developers with many smaller applications. It expects you to build your own application that will use the online backend pro- vided by them. They ensure this by providing APIs for most plat- forms and making it easy for developers to setup, use and operate the cloud backend. This allows the developers to focus solely on his application. This is one of the companies that offer free starting ac- count, with future pricing increase depending on number of users that will be using your application per month.

Parse Parse7 is one of the first BaaS providers on the market and one of the biggest. It offers good documentation, and provides an easy to use APIs for developers that allows them to focus only on the fron- tend of their application. It offers good online application where you

4. http://www.feedhenry.com/ 5. https://github.com/ - Online project hosting 6. http://www.kinvey.com/ 7. https://parse.com/

12 3. BAAS SERVICES can access each of your applications separately, view the database, cloud code, notifications and analytics. Parse offers a free starter ac- count that supports 30 API calls per second, anything higher will incur charges. The main disadvantage of Parse is that the pricing can get very high with an increasing number of users of your applica- tion. As this is my service of choice it will be described in detail in the next chapter.

3.3 Parse

The aim of this work is to create an application with an interactive online database used to store data about users. In order to do this, I had to choose between creating my own database and running a server, or using a BaaS service with already created infrastructure. Due to the fact that I did the application alone I did not have the resources to consider creating my own backend, so I decided to go with a BaaS provider. My choice was a company named Parse.

The reasoning behind my choice is that I needed a relatively sim- ple feature set. The main requirement was a database with reason- able pricing and preferably with a free basic account. These require- ments are fulfilled both by Kinvey and Parse described in the pre- vious chapter, so I was choosing between these two. Both of these companies offer a similar approach to their service, with a slight dif- ferentiation in pricing options. While Kinvey’s pricing is based on number of active users, Parse is charging based on API calls. Due to the nature of this application, which can have a lot of users that use it sparsely generating just a small number of API calls, I decided to go with Parse.

3.3.1 Features description All of Parse features are available under one account. These features are divided in three core areas, consisting of Parse Core, Parse Push and Parse Analytics. Parse Core is dealing with everything your ap- plication needs on the server, like saving and retrieving data, run- ning code online or managing your database. Parse Push is handling

13 3. BAAS SERVICES

push notifications for your applications, and Parse Analytics is about monitoring your application status and events.

Dashboard The dashboard serves as an online tool which is used to provide con- trol over your applications. It provides an overview of all the ap- plications, with an option to manage them separately. It allows you to manage your database, view cloud code and manage background jobs. It also allows you to view the Analytics for your application and manage notifications. A big part of the dashboard is the online documentation8 containing all the information needed to use Parse in your application.

Database Parse database is based on MongoDB9. This provides a scalable data- base composed of documents, a data structure similar to JSON ob- jects composed of field and value pairs, as shown in [2]. This al- lows for creation of traditional relational databases as well as cus- tom made databases suited for different needs. The contents of the database are accessed using Parse API, with queries similar to tradi- tional SQL10. More about how to access and use the database will be described later in this chapter.

Cloud Code Parse is providing a service called Cloud Code, that lets you run JavaScript code in the cloud. This allows you to run extra server-side logic with provided Parse JavaScript SDK. This allows for example modification of objects after saving them in the database, or modi- fying them when requested from the database. Part of Cloud Code are also background jobs which lets you schedule recurring tasks,

8. https://www.parse.com/docs 9. Open-source document database [2] 10. Structured Query Language

14 3. BAAS SERVICES like sending emails or perform long running computations at spe- cific time intervals.

Parse Push Parse Push lets you send push notifications across different devices. It is controlled via an easy online interface that is part of the Parse dashboard, allowing everyone to send notifications easily. It also pro- vides means to schedule future notifications, as well as advanced tar- geting providing you with options to segment your customers and target them specifically. A part of the feature set is also Push Experi- ments, which allow you to test the notifications on your own device, before you send them to your customers.

Parse Analytics The analytics allow you to track your application performance in real-time. It is available in Parse Dashboard, where you can see well structured data in graphs that allows you to analyze deeply how your application performs. It includes analysis of active installations, API calls, user activity, Push notifications and more. Other major fea- ture being the ability to find crashes, as Parse allows you to view not only the number of crashes, but also to track the sources of the crash, logs and metadata that should allow you to debug and fix your code.

Pricing I have talked briefly about pricing options already, but here is a com- plete description of pricing options. Parse offers an online tool11 that shows you how much the service will cost you. The basic option is free, and provides you with a limit of 30 API calls per second, 1 back- ground job and database storage of 20GB. After your application reaches these limits, it costs $100 more per 10 API calls, and $200 per 20GB of data. Separate pricing is used for push notification, where the free version allows you to have 1,000,000 unique recipients, with $5 per 100,000 extra recipients.

11. https://parse.com/plans

15 3. BAAS SERVICES

3.3.2 Usage Here I will provide an example how the Parse API works when de- veloping an iOS application. The example code used is based on the online documentation [3] provided by Parse.

The first step in using Parse SDK is to download the SDK from their website, and adding the Parse framework to your application. Then it is simply about linking your application to the online back- end using applicationID and clientKey provided by Parse. This is done by sending a message [Parse setApplicationId: appID clientKey: clientKey]; somewhere during the inicialization of your application. Later on you are able to use all API functions by including Parse framework using: #import

Later the interaction with the database is done using queries and PFObject. PFObject is a structure that represents a single object in the database. The creation of a PFObject and saving it to the database is shown in Code 3.1. This code creates a PFObject that will be stored in database named GameScore with attributes score and playerName. The actual saving of the object to an online database is done using message saveInBackgroundWithBlock. When the object is saved to the online database, it is automatically assigned a unique identifier objectId, and date stamps createdAt and updatedAt.

Retrieving of objects from the database is done using PFQuery as seen in Code 3.2. Objects can be retrieved based on their objectId using function getObjectInBackgroundWithId: objectId, which re- turns a single object. Other option is to formulate a query with condi- tions that allows you to retrieve an array of PFObjects based on these conditions using findObjectsInBackgroundWithBlock.

Updating objects is performed using the combination of querying for the object and than using the save method that was described in Code 3.1. Removal of an object from the database is done using message [gameScore deleteInBackground];

16 3. BAAS SERVICES

Code 3.1: PFObject creation and saving PFObject *gameScore = [PFObject objectWithClassName:@"GameScore" ]; gameScore[@"score"] = @1337; gameScore[@"playerName"] = @"Sean P l o t t " ; [gameScore saveInBackgroundWithBlock : ^(BOOL succeeded , NSError * e r r o r ) { i f (succeeded) { // The object has been saved. } else { //There was a problem, check error.description } }];

Code 3.2: PFObject querying PFQuery *query = [PFQuery queryWithClassName:@"GameScore" ]; [query getObjectInBackgroundWithId :@"xWMyZ4YEGZ" block:^(PFObject *gameScore , NSError * e r r o r ) { NSLog(@"%@" , gameScore ); }];

This is just a quick introduction to working with Parse, as it de- scribes only the core functions required for working with their on- line backend. There are many more functions for manipulating with objects, such as special forms of queries, or possibility to query and save PFObjects in background. They are all described in detail in the online documentation [3] provided by Parse.

17 4 Application

Nowadays in a world full of social networks it seems almost impos- sible to gather all the information about a person in a single place. Of course today’s smartphones have the ability to store this information in the address book, but it seems as a rather unpleasant work to fill in all the information for each contact. Therefore it would be great if everyone had to fill only the information about himself that he wants to share, and everyone could simply get the up-to-date information from his friends.

The idea was therefore to create an application that would allow the user to create his own profile that would be saved in an online database. He would then share his profile with his friends that would be spared of the tedious task of gathering all the information them- selves. Another benefit would be that if the user changes any of his personal information, all his friends would get the updated infor- mation immediately from the online database. The choice of iOS as a development target comes from the fact, that iOS has smaller frag- mentation1, a smaller range of devices, and larger and more affluent fan base [5].

4.1 Existing solutions

Due to the unique nature of my application, it is hard to find an al- ready existing solution to this specific problem. There exist many dif- ferent contact managers for iOS, but all they usually provide is the ability to manage your already created address book. There exists only one application in the AppStore that provides at least a similar functionality as my application.

This application is called FullContact, and is described as unified address book, giving you a complete picture of your from your phone and social networks, as posted in the official description [14]. The main feature of this application is that it tries to gather as

1. As described in 2.1.1 18 4. APPLICATION

much information as possible from different social network sites and save it in one place. It synchronizes contacts from your phone ad- dress book and GMail account2, and adds the relevant information to them. It provides a simple, unique design and is easy to use. The basic version of the application is available for free, and features also a paid version with premium features.

Figure 4.1: FullContact [14]

After analyzing the market it is clear that creating such applica- tion is a good move, as it provides a truly unique functionality. In order to make sure that the basic principles of the application are right, I have performed a SWOT analysis:

Strength Unique functionality, easy to use, simple UI and design

Weakness Requires a large number of users to be effective

Opportunities Core functionality is simple but can be extended by more features

Threats With big number of users can become expensive to support with paid backend and no revenues

2. https://www.gmail.com

19 4. APPLICATION 4.2 Analysis and Design

4.2.1 Analysis

The core feature of this application is sharing of own profile, and viewing profiles of friends. This should be the main focus of the en- tire application and everything else should be built around these core features. In order to satisfy these two features, I need to introduce a few sub-features, as I call them.

The profile feature should consist of profile creation, viewing, edit- ing and deletion. The creation of one’s profile should be performed immediately after running the application for the first time, since the features work only with a created profile. The editing of the pro- file should be possible anytime during the usage of the application, along with the possible deletion of the profile, if the user wants to erase his profile from the online database.

The second part is viewing other people’s profiles. The application should distinguish between approved and foreign contacts. When you have approved someone to view your profile, he should be able to see all the information you have provided in your profile. Other- wise, if you try to look at a contact that is not approved, you should only be able to see the core information required to identify the per- son (name, phone number and profile image).

Apart from these features, the application should let you search for people based on their name or phone number. It should also allow you to invite people who are not yet using your application, using an invitation message or email. One of the requirements was for it to be able to run offline, which means that I needed to incorporate some sort of offline storage of contacts, so they can be viewed when offline. The last decision was about pricing, whether the application should be free or paid. In order to attract as many users as possible and thus fill the database with as much profiles as possible, I decided to provide the application for free.

20 4. APPLICATION

4.2.2 Design As described in the analysis part, the application offers just a small number of functions, but they need to be implemented perfectly. The most important part was choosing an appropriate BaaS service, be- cause most of the operations are going to take place online. This choice was described in detail in the previous chapter. As an opposite side to this online service, it was necessary to choose a way of stor- ing the data offline on the device. This is handled by using CoreData framework of iOS, that allows to store data in a similar way to tradi- tional SQL.

In terms of the actual visual design of the application itself, the choice was made to go with a simple style using many of the visual elements already provided by XCode. This has two reasons, one is to simplify the creation of the application, since I would be able to use already created elements. The other reason is to provide a visual style that resembles the core iOS experience as much as possible, so the users would feel comfortable using the application. This approach is used also in the actual views3, that are made in a way to look similar like in core iOS applications.

When the application is launched, it distinguishes between two basic situations. If the application is run for the first time, or if there doesn’t exist any local profile, the application will start with an in- troductory screen, and then continue through profile creation. There is also an option to retrieve a profile from a database, in case the user has switched to a different device or had to reinstall the application. After the profile creation, the application continues to the main view. If upon launch the application finds an existing profile, it goes di- rectly to the main view. The main view represents the address book with other people’s profiles. From thereon, the user can go directly to viewing his own profile, searching and handling pending contact requests. Possible operations in the application are described in the diagram in Figure 4.2.

3. View is one screen in the application, e.g. contact view, profile creation, ..

21 4. APPLICATION

Figure 4.2: Use case diagram

4.3 Implementation

Before I begin describing how the application works, it would be best to first explain the interactions between the frontend and the backend, that means the data management and the synchronization with online server.

4.3.1 Data management and synchronization

The data structure in my application is divided in to three different formats, that are interacting together. The information about the local user is stored in a file Profile.plist. Its type is property list, which is a data format used in XCode, that is similar to Json. All the informa- tion contained in the profile is stored as basic data types, like strings, byte data, date or array. The data, containing information about other people’s profiles, is stored locally in the system, using the CoreData

22 4. APPLICATION framework. It is contained in a single database that contains all the information about the profiles, so it can be accessed offline. This of- fline data stores information only about the people in the phone’s address book, or people who shared their information with the user. All of this data is synchronized with an online database hosted on Parse. This online database has almost the same structure as the of- fline database stored in CoreData.

The logic behind this distribution to three different places is as fol- lows. The user is only able to edit his own profile, so all the modifi- cations and data are stored inside the single file Profile.plist. The contents of this file are then uploaded to the online database, that col- lects all the data from all users. The CoreData database then serves as a mirror for the data gathered from the online database and from the phone’s address book, that are later displayed to the user using the application.

Synchronization All the interaction with the online database, and the synchroniza- tion logic is in the class SyncManager. It is a singleton class, so it can be instantiated and used anywhere in the application. The synchro- nization itself consists of two parts. One part is the gathering of con- tact data from the phone’s address book (called local synchronization), the other part is the synchronization with the online database (online synchronization). Both these operations are independent of each other, but they both work with the same local database, so they need to function together correctly.

The local synchronization is done using the method (void) syncWithAddressBook. It requires having granted access to address book by the user, otherwise it will not run. The main part of the method is a cycle, that iterates through the entire address book, and deals with the contacts one by one. It then tries to categorize the contact, using a basic set of rules. First, it checks if that contact al- ready exists in the database. If it is already in the database and if it is not already updated from the online database, it will replace the

23 4. APPLICATION

contact. If it doesn’t find a contact in the database, it can mean either that the contact does not exist in the database, or that it is a contact that was synchronized from the online database. Therefore it per- forms a check whether the database contains a contact with the same phone number. If there is already a contact with that phone number, it means that it’s an online contact and shouldn’t be replaced. Oth- erwise if it doesn’t find a matching phone number it will add the contact from the address book to the database. Using this method should ensure that the database is always up to date with the ad- dress book, and that it does not necessarily create duplicates that can be evaded.

The online synchronization is handled in the method (BOOL) sync. This method was changed many times during the development in order to adapt to the changes in code. There are two different possi- bilities for handling the synchronization, as it needs to manage dif- ferent levels of privacy. One method is to create different queries and retrieve only partial sets of profiles from the online database. The other method combines these queries into one, and handles the cat- egorization of the results later. I have decided to go with the second method for two reasons. One reason is that it reduces the number of API calls from three to one (Parse is limiting number of API calls), the other one is that it allows me to handle connection errors better. As I already said, the method is consisted of three different queries. The approvedQuery is used to fetch profiles from your already ap- proved contacts. Those are the contacts that have your objectId con- tained in their approvedContacts array property stored online. These contacts are being fully synchronized with all data. The second query is called idQuery, and it is used to fetch contacts for which you have their objectId available, but who have not approved you. These pro- files synchronize only their name, phone number and profile image. The last query called phonesQuery is used to try and find contacts in your local database, that are already using this application. It does so by searching for a matching phone number in the online database, and if it finds one it will synchronize a partial profile to your local database. These three queries are then combined into a single query using logical OR operation. If the query was succesfull it will return

24 4. APPLICATION

an array of PFObjects which needs to be split again using the same rules as in the queries, and then one by one synchronized with the local database.

The crucial part for preserving the integrity of the local database is that the local and online synchronization should never run at the same time, as it could create unwanted duplicates in the database. It is also preferred for the local synchronization to run first, as it doesn’t require internet connection and therefore should finish faster. The updated database from the local synchronization can be then more accurately used in the online synchronization. There is also an- other synchronization method in the code called (void) requestsSync that is used to fetch pending requests from the database. Its functionality is simple, as it fetches all the requests where the destination objectId matches this user’s ObjectId and will not be described in detail.

4.3.2 User Interface

While the user interface is an important part of this application and is crucial for its success, I will not go into very specific details. The whole user interface is based on the idea that it should be as familiar to new users as possible. This is achieved by making the views seem similar to those used in core iOS applications, like the address book. This means that the profile edit is looking very similar to contact cre- ation in address book, or that the contact detail view matches the contact detail view in address book. Other than that, the user inter- face maintains its integrity by using similar set of colors and shapes. The specific details for each view will be described later. The user interface can be seen in Appendix A.

4.3.3 Classes and Views

Here I will describe all the important classes and their important methods, as well as their associated views.

25 4. APPLICATION

AppManager class

This is the core manager class that is used in all iOS applications. It handles the functionality that happens when launching or activating the application. The functionality it brings to this application is that it runs the synchronizations when the application is launched using the methods mentioned in Subsection 4.3.1, and it decides whether to show the introductory screen if there is no local profile created.

Introduction and profile creation

The introduction screen presents two options. One is to retrieve an already existing profile, the other is to create a new one. When choos- ing the create profile option, the user is presented with a new screen used to gather the required information from him (phone number, country and password). The logic is done in class CreateParseObjectViewController. When moving to the next view, the method continueButton checks whether all the required fields are properly filled and then creates a profile in the online database. The phone needs to be connected to the internet in order to con- tinue. Then it presents another view controller, with a matching class named CreateProfileTableViewController that allows the user to complete his profile. None of the information here is required, but the view is designed in a way that the user will need to scroll all the way down to continue. This should make him look at all the options and make him fill at least some information. The other option that can be accessed from the introduction screen is retrieve profile view. This view is using RetrieveViewController class and it allows the user to retrieve his profile based on his phone number and password he set when creating the profile. It queries for the profile in the online database and if found, it loads it into the application.

Main screen

The main screen of the application is divided into three basic views, using Tab Bar. A tab bar is a bar at the bottom of the screen, with which we can switch between different views.

26 4. APPLICATION

Contacts The first tab contains a table populated by the local database. It is im- plemented using AddressBookTableViewController class. This table displays the contents of the local database, as well as a refresh con- trol used to refresh and synchronize the contents of the database. Through this table, we can access details of a contact as well as ac- cess our own profile.

Profile edit The profile editing screen is similar to the one I used in profile cre- ation, with only small differences in buttons used and features avail- able. It allows the user to change all the information including the basic identifiers, phone number and country code. The logic is in ProfileEditTableViewController, and contains two significant fea- tures. One is saving of the profile, which done using method (void) saveProfile, the other being profile deletion done by using (void) deleteProfileAction. The profile update needs to deal with the situation when the user changes his phone number. As the phone number is a unique identifier of each user, it mustn’t be contained twice in the database. So the saveProfile method first checks for possible conflicts in the online database and only then saves the up- dated profile. The method for deleting the profile is specific in the way that it first needs to make sure that the profile was really deleted from the online database. If it was deleted, it will then erase both the local database and local profile, and redirect the user back to the in- troduction screen.

Search The search view is the second tab in the tab bar. It allows the user to search both in the offline and online database. The search method is located in SearchViewController class under the name (void)fetchSearchResults. This method is activated by clicking the search button, and performs two separate searches. The offline search will look through the local database for occurrences of the search string in names and phone . The online search is a bit more

27 4. APPLICATION

complicated. It is done using standard PFQuery, but it only searches for whole names of whole phone numbers. This restriction is there due to the fact that we don’t want users to search for people they don’t know, and gather personal information freely.

Requests This is the third tab in the tab bar. It is dealing with requests, as it displays pending requests for the user’s profile in a table. This data is again grabbed from the local database, that is synchronized us- ing the requestsSync method from SyncManager. After reviewing the contact detail of the requesting user in a detailed view, the user can choose to accept or decline a request. If the user accepts a re- quest, the objectId of the person requesting the profile is added to ApprovedContacts array and will synchronize to the other user’s ap- plication at the next synchronization. If the request is declined, the application deletes it from the online database and doesn’t deal with it anymore.

4.3.4 Settings This application uses the Settings application available in iOS. This application provides developers with a place where they can put the options for their application. This is done using the framework pro- vided by Apple, which then allows you to create a property list file with your settings. These settings can be then accessed in your code using the NSUserDefaults class. This application uses only two op- tions in settings, one being the option to hide the contacts that are not using this application, and the other one being the option to turn on or off the synchronization with local address book.

4.4 Testing

One of the most important parts of application development is test- ing. Apple provides the developers with a simple and easy way to test their application. Apart from the traditional testing on a phone connected to the developer’s computer, it is possible to conduct in-

28 4. APPLICATION ternal and external testing of your application with other people. Us- ing iTunes Connect4 and it’s associated application TestFlight [12] it is possible to invite other people to test your application. When you have an application ready for testing, you upload it to iTunes Con- nect and there you can choose the form of testing you want to do. Internal testing is for a small number (up to 25) people, who all need to be part of your account. External testing should be used for testing a finalized application, as it allows you to send it to up to 1,000 people, but it needs to be approved by Apple. iTunes Connect allows you to upload several builds of your application and test them as you implement new functions. The testers only need to have the TestFlight application installed on their phones and they should be able to download the latest version of the application you invited them to. It is then possible to gather testing data as perfor- mance, crash logs or network usage.

The testing of this application was done locally throughout the de- velopment, with the implementation of each new feature. When the application was finished regarding its features, I started testing it in- ternally on about five different devices with three different people. This internal testing revealed many bugs and missing features that wouldn’t be spotted while testing it alone. With all the major bugs fixed, the application is now in the final external testing phase before it will be released to AppStore.

4. https://itunesconnect.apple.com

29 5 Conclusion

The aim of this work was to create an application for iOS that would provide an easy way to gather contact information from your friends. The application complies to the requirements that were established in the analysis section and in the description of this thesis. The ap- plication was thoroughly tested using internal testing with three dif- ferent people and five different devices. The application is running smoothly without any significant issues that would cause it to crash.

The application is now in the state of external testing where it will be made available to a bigger number of users. After the external testing period the application will be made publicly available in the AppStore. The work on this application will not end with this thesis, as there are many more features that can and will be implemented in this application. It is also supposed that after the public launch there may occur more bugs and problems that will need to be fixed. The next major step will be to create a website that will promote this application, and porting the application to other major platforms An- droid and Windows Phone.

When working on the application it was necessary to learn pro- gramming for iOS, and how to analyze and design a good applica- tion. The advantage and at the same time disadvantage of this appli- cation is its uniqueness, because I wasn’t able to compare it to other available solutions. This is where I put to use my knowledge of how to design good UI. This application provides a solid solution for the problem of gathering diverse contact information from your friends.

30 Bibliography

[1] Backend as a Service (BaaS) [online]. http://baas. apievangelist.com, 2015. Accessed: 23/4/2015. [2] Introduction to MongoDB [online]. http://docs.mongodb.org/ manual/core/introduction/, 2015. Accessed: 28/4/2015. [3] Parse documentation [online]. https://parse.com/docs/ios_ guide#objects/iOS, 2015. Accessed: 30/4/2015. [4] Scott Densmore. Why singletons are evil [online]. http://blogs.msdn.com/b/scottdensmore/archive/2004/ 05/25/140827.aspx, 2004. Accessed: 20/4/2015. [5] Matthew Hamlyn. Should You Develop for Android, iOS or both? AppMakr, 2014. [6] Mathew Honan. Apple unveils iPhone. Macworld, 2007. [7] Apple Inc. App review [online]. https://developer.apple. com/app-store/review/, 2015. Accessed: 20/4/2015. [8] Apple Inc. distribution [online]. https: //developer.apple.com/support/appstore, 2015. Accessed: 20/4/2015. [9] Apple Inc. iOS Distribution [online]. https://developer. apple.com/programs/ios/distribute.html, 2015. Accessed: 20/4/2015. [10] Apple Inc. iTunes Connect [online]. https://developer. apple.com/library/prerelease/ios/documentation/ LanguagesUtilities/Conceptual/iTunesConnect_Guide/ Chapters/About.html, 2015. Accessed: 20/4/2015. [11] Apple Inc. Start Developing iOS Apps Today [on- line]. https://developer.apple.com/library/ios/ referencelibrary/GettingStarted/RoadMapiOS/index.html# //apple_ref/doc/uid/TP40011343-CH2-SW1, 2015. Accessed: 20/4/2015.

31 BIBLIOGRAPHY

[12] Apple Inc. TestFlight [online]. https://itunes.apple.com/cz/ app/testflight/id899247664?mt=8, 2015. Accessed: 5/5/2015.

[13] Apple Inc. Xcode features [online]. https://developer.apple. com/xcode/features, 2015. Accessed: 20/4/2015.

[14] FullContact Inc. FullContact - Better Contact Management for iOS [online]. https://itunes.apple.com/app/fullcontact/ id579616837, 2015. Accessed: 2/5/2015.

[15] Kin Lane. Overview Of The Backend as a Service (BaaS) Space. White Paper, May 2013.

[16] Nilay Patel. iPhone OS 4 renamed iOS 4, launching June 21 with 1500 new features. , 2010.

[17] John Siracusa. Can’t help falling in love. Ars Technica, 2008.

[18] Neil Smyth. Objective-C 2.0 Essentials - Third Edition: A Guide to Modern Objective-C Development [online]. CreateSpace In- dependent Publishing Platform, 2012.

32 A Application screenshots

33 A.APPLICATION SCREENSHOTS

34 A.APPLICATION SCREENSHOTS

35 A.APPLICATION SCREENSHOTS

36