Quantcast
Channel: Envato Tuts+ Code - Mobile Development
Viewing all 1836 articles
Browse latest View live

New Course: Get Started Coding Android Apps With Kotlin

$
0
0

In our new course, Get Started Coding Android Apps With Kotlin, you will learn how to create a simple app with Kotlin. Your instructor, Annapurna Agrawal, will give you a comprehensive, practical introduction to this powerful language. 

You'll start by installing Android Studio with the Kotlin plugins in order to create and run your first Android app. You'll then go on to learn some of the basics of views and layouts in Android, how to use Android Intents, and how to use some of Kotlin's special features to write safer, more concise code. By the end of this course, you'll be able to use Android and Kotlin to build a basic app with cleaner code.

Get Started Coding Android Apps With Kotlin

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 550,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

 

2018-06-07T06:25:16.000Z2018-06-07T06:25:16.000ZAndrew Blackman

New Course: Get Started Coding Android Apps With Kotlin

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31257

In our new course, Get Started Coding Android Apps With Kotlin, you will learn how to create a simple app with Kotlin. Your instructor, Annapurna Agrawal, will give you a comprehensive, practical introduction to this powerful language. 

You'll start by installing Android Studio with the Kotlin plugins in order to create and run your first Android app. You'll then go on to learn some of the basics of views and layouts in Android, how to use Android Intents, and how to use some of Kotlin's special features to write safer, more concise code. By the end of this course, you'll be able to use Android and Kotlin to build a basic app with cleaner code.

Get Started Coding Android Apps With Kotlin

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 550,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

 

2018-06-07T06:25:16.000Z2018-06-07T06:25:16.000ZAndrew Blackman

Building a Shopping List Application With CloudKit: Adding Relationships

$
0
0

In the previous tutorial of this series, we added the ability to add, update, and remove shopping lists. A shopping list without any items in it isn't very useful, though. In this tutorial, we'll add the ability to add, update, and remove items from a shopping list. This means that we'll be working with references and the CKReference class.

We'll also take a closer look at the data model of the shopping list application. How easy is it to make changes to the data model, and how does the application respond to changes we make in the CloudKit Dashboard?

Prerequisites

Remember that I will be using Xcode 7 and Swift 2. If you are using an older version of Xcode, then keep in mind that you are using a different version of the Swift programming language.

In this tutorial, we will continue where we left off in the second tutorial of this series. You can download or clone the project from GitHub.

1. Shopping List Details

Currently, the user can modify the name of a shopping list by tapping the detail disclosure indicator, but the user should also be able to see the contents of a shopping list by tapping one in the lists view controller. To make this work, we first need a new UIViewController subclass.

Step 1: Creating ListViewController

The ListViewController class will display the contents of a shopping list in a table view. The interface of the ListViewController class looks similar to that of the ListsViewController class. We import the CloudKit and SVProgressHUD frameworks and conform the class to the UITableViewDataSource and UITableViewDelegate protocols. Because we'll be using a table view, we declare a constant, ItemCell, that will serve as a cell reuse identifier.

We declare three outlets: messageLabel of type UILabel!tableView of type UITableView!, and activityIndicatorView of type UIActivityIndicatorView!. The list view controller keeps a reference to the shopping list it is displaying in the list property, which is of type CKRecord!. The items in the shopping list are stored in the items property, which is of type [CKRecord]. Finally, we use a helper variable, selection, to keep track of which item in the shopping list the user has selected. This will become clear later in this tutorial.

Step 2: Creating the User Interface

Open Main.storyboard, add a view controller, and set its class to ListViewController in the Identity Inspector. Select the prototype cell of the lists view controller, press the Control key, and drag from the prototype cell to the list view controller. Choose Show from the menu that pops up, and set the identifier to List in the Attributes Inspector.

Add a table view, a label, and an activity indicator view to the view controller's view. Don't forget to wire up the outlets of the view controller as well as those of the table view.

Select the table view and set Prototype Cells to 1 in the Attributes Inspector. Select the prototype cell, and set Style to Right Detail, Identifier to ItemCell, and Accessory to Disclosure Indicator. This is what the view controller should look like when you're finished.

List View Controller

Step 3: Configuring the View Controller

Before we revisit the CloudKit framework, we need to prepare the view controller for the data it's going to receive. Start by updating the implementation of viewDidLoad. We set the view controller's title to the name of the shopping list and invoke two helper methods, setupView and fetchItems.

The setupView method is identical to the one we implemented in the ListsViewController class.

While we're at it, let's also implement another familiar helper method, updateView. In updateView, we update the user interface of the view controller based on the items stored in the items property.

I'm going to leave fetchItems empty for now. We'll revisit this method once we're finished setting up the list view controller.

Step 4: Table View Data Source Methods

We're almost ready to take the application for another test run. Before we do, we need to implement the UITableViewDataSource protocol. If you've read the previous installments of this series, then the implementation will look familiar.

Step 5: Handling Selection

To tie everything together, we need to revisit the ListsViewController class. Start by implementing the tableView(_:didSelectRowAtIndexPath:) method of the UITableViewDelegate protocol.

We also need to update prepareForSegue(segue:sender:) to handle the segue we created a few moments ago. This means that we need to add a new case to the switch statement.

To satisfy the compiler, we also need to declare the SegueList constant at the top of ListsViewController.swift.

Build and run the application to see if everything is wired up correctly. Because we haven't implemented the fetchItems method yet, no items will be displayed. That's something we need to fix.

2. Fetching Items

Step 1: Create a Record Type

Before we can fetch items from the CloudKit backend, we need to create a new record type in the CloudKit Dashboard. Navigate to the CloudKit Dashboard, create a new record type, and name it Items. Each item should have a name, so create a new field, set the field name to name, and set the field type to String.

Each item should also know to which shopping list it belongs. That means each item needs a reference to its shopping list. Create a new field, set the field name to list, and set the field type to Reference. The Reference field type was designed for this exact purpose, managing relationships.

Item Record Type

Head back to Xcode, open ListsViewController.swift, and declare a new constant at the top for the Items record type.

Step 2: Fetching Items

Open ListViewController.swift and navigate to the fetchItems method. The implementation is similar to the fetchLists method of the ListsViewController class. There is an important difference, though.

The difference between fetchItems and fetchLists is the predicate we pass to the CKQuery initializer. We're not interested in every item in the user's private database. We're only interested in the items that are associated with a particular shopping list. This is reflected in the predicate of the CKQuery instance.

We create the predicate by passing in a CKReference instance, which we create by invoking init(recordID:action:). This method accepts two arguments: a CKRecordID instance that references the shopping list record and a CKReferenceAction instance that determines what happens when the shopping list is deleted.

Reference actions are very similar to delete rules in Core Data. If the referenced object (the shopping list in this example) is deleted, then the CloudKit framework inspects the reference action to determine what should happen to the records that hold a reference to the deleted record. The CKReferenceAction enum has two member values:

  • None: If the reference is deleted, nothing happens to the records referencing the deleted record.
  • DeleteSelf: If the reference is deleted, every record referencing the deleted record is also deleted.

Because no item should exist without a shopping list, we set the reference action to DeleteSelf.

The processResponseForQuery(records:error:) method contains nothing new. We process the response of the query and update the user interface accordingly.

Build and run the application. You won't see any items yet, but the user interface should update to reflect that the shopping list is empty.

3. Adding Items

Step 1: Creating AddItemViewController

It's time to implement the ability to add items to a shopping list. Start by creating a new UIViewController subclass, AddItemViewController. The interface of the view controller is similar to that of the AddListViewController class.

At the top, we import the CloudKit and SVProgressHUD frameworks. We declare the AddItemViewControllerDelegate protocol, which will serve the same purpose as the AddListViewControllerDelegate protocol. The protocol defines two methods, one for adding items and one for updating items.

We declare two outlets, a text field and a bar button item. We also declare a property for the delegate and a helper variable, newItem, that helps us determine whether we're creating a new item or updating an existing item. Finally, we declare a property list for referencing the shopping list to which the item will be added and a property item for the item we're creating or updating.

Before we create the user interface, let's implement two actions that we'll need in the storyboard, cancel(_:) and save(_:). We'll update the implementation of the save(_:) action later in this tutorial.

Step 2: Creating the User Interface

Open Main.storyboard, add a bar button item to the navigation bar of the list view controller, and set System Item to Add in the Attributes Inspector. Drag a view controller from the Object Library and set its class to AddItemViewController. Create a segue from the bar button item we just created to the add item view controller. Choose Show from the menu that pops up, and set the segue's identifier to ItemDetail.

Add two bar button items to the navigation bar of the add item view controller, a cancel button on the left and a save button on the right. Connect each bar button item to its corresponding action. Add a text field to the view controller's view and don't forget to connect the outlets of the view controller. This is what the add item view controller should look like when you're finished.

Add Item View Controller

Step 3: Configuring the View Controller

The implementation of the add item view controller contains nothing that we haven't covered yet. There's one exception, though, which we'll discuss in a moment. Let's start by configuring the view controller in viewDidLoad.

We invoke setupView, a helper method, and update the value of newItem. If the item property is equal to nilnewItem is equal to true. This helps us determine whether we're creating or updating a shopping list item.

We also add the view controller as an observer for notifications of type UITextFieldTextDidChangeNotification. This means that the view controller is notified when the contents of the nameTextField change.

In viewDidAppear(animated:), we show the keyboard by calling becomeFirstResponder on nameTextField.

The setupView method invokes two helper methods, updateNameTextField and updateSaveButton. The implementation of these helper methods is straightforward. In updateNameTextField, we populate the text field. In updateSaveButton, we enable or disable the save button based on the contents of the text field.

Before we take a look at the updated implementation of the save(_:) method, we need to implement the textFieldDidChange(_:) method. All we do is invoke updateSaveButton to enable or disable the save button.

Step 4: Saving Items

The save(_:) method is the most interesting method of the AddItemViewController class, because it shows us how to work with CloudKit references. Take a look at the implementation of the save(_:) method below.

Most of its implementation should look familiar since we covered saving records in the AddListViewController class. What interests us most is how the item keeps a reference to its shopping list. We first create a CKReference instance by invoking the designated initializer, init(recordID:action:). We covered the details of creating a CKReference instance a few minutes ago when we created the query for fetching shopping list items.

Telling the item about this reference is easy. We invoke setObjec(_:forKey:) on the item property, passing in the CKReference instance as the value and "list" as the key. The key corresponds to the field name we assigned in the CloudKit Dashboard. Saving the item to iCloud is identical to what we've covered before. That's how easy it is to work with CloudKit references.

The implementation of processResponse(record:error:) contains nothing new. We check to see if any errors popped up and, if no errors were thrown, we notify the delegate.

Step 5: Updating ListViewController

We still have some work to do in the ListViewController class. Start by conforming the ListViewController class to the AddItemViewControllerDelegate protocol. This is also a good moment to declare a constant for the segue with the identifier ItemDetail.

Implementing the AddItemViewControllerDelegate protocol is trivial. In controller(_:didAddItem:), we add the new item to items, sort items, reload the table view, and invoke updateView.

The implementation of controller(_:didUpdateItem:) is even easier. We sort items and reload the table view.

In sortItems, we sort the array of CKRecord instances by name using the sortInPlace function, a method of the MutableCollectionType protocol.

There are two more features we need to implement: updating and deleting shopping list items.

Step 6: Deleting Items

To delete items, we need to implement tableView(_:commitEditingStyle:forRowAtIndexPath:) of the UITableViewDataSource protocol. We fetch the shopping list item that needs to be deleted and pass it to the deleteRecord(_:) method.

The implementation of deleteRecord(_:) doesn't contain anything new. We invoke deleteRecordWithID(_:completionHandler:) on the private database and process the response in the completion handler.

In processResponseForDeleteRequest(record:recordID:error:), we update the items property and the user interface. If something went wrong, we notify the user by showing an alert.

Step 7: Updating Items

The user can update an item by tapping the detail disclosure indicator. This means we need to implement the tableView(_:accessoryButtonTappedForRowWithIndexPath:) delegate method. In this method, we store the user's selection and manually perform the ListDetail segue. Note that nothing happens in the tableView(_:didSelectRowAtIndexPath:) method. All we do is deselect the row the user tapped.

In prepareForSegue(_:sender:), we fetch the shopping list item using the value of the selection property and configure the destination view controller, an instance of the AddItemViewController class.

That's all we need to do to delete and update shopping list items. In the next section, we explore how easy it is to update the data model in the CloudKit Dashboard.

4. Updating the Data Model

If you've ever worked with Core Data, then you know that updating the data model should be done with caution. You need to make sure you don't break anything or corrupt any of the application's persistent stores. CloudKit is a bit more flexible.

The Items record type currently has two fields, name and list. I want to show you what it involves to update the data model by adding a new field. Open the CloudKit Dashboard and add a new field to the Items record. Set field name to number and set the field type to Int(64). Don't forget to save your changes.

Update Item Record Type

Let's now add the ability to modify an item's number. Open AddItemViewController.swift and declare two outlets, a label and a stepper.

We also need to add an action that is triggered when the stepper's value changes. In numberDidChange(_:), we update the contents of numberLabel.

Open Main.storyboard and add a label and a stepper to the add item view controller. Connect the outlets of the view controller to the corresponding user interface elements and connect the numberDidChange(_:) action to the stepper for the Value Changed event.

Update Add Item View Controller

The save(_:) action of the AddItemViewController class also changes slightly. Let's see what that looks like.

We only need to add two lines of code. At the top, we store the value of the stepper in a constant, number. When we configure item, we set number as the value for the "number" key, and that's all there is to it.

We also need to implement a helper method to update the user interface of the add item view controller. The updateNumberStepper method checks if the record has a field named number and updates the stepper if it does.

We invoke updateNumberStepper in the setupView method of the AddItemViewController class.

To visualize the number of each item, we need to make one change to the ListViewController. In tableView(_:cellForRowAtIndexPath:), we set the contents of the cell's right label to the value of the item's number field.

That's all we need to do to implement the changes we made to the data model. There's no need to perform a migration or anything like that. CloudKit takes care of the nitty gritty details.

Conclusion

You should now have a proper foundation in the CloudKit framework. I hope you agree that Apple has done a great job with this framework and the CloudKit Dashboard. There's a lot that we haven't covered in this series, but by now you've learned enough to jump in and get started with CloudKit in your own projects.

If you have any questions or comments, feel free to leave them in the comments below or reach out to me on Twitter.

2018-06-07T13:33:57.000Z2018-06-07T13:33:57.000ZDoron Katz

Building a Shopping List Application With CloudKit: Adding Relationships

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-25342

In the previous tutorial of this series, we added the ability to add, update, and remove shopping lists. A shopping list without any items in it isn't very useful, though. In this tutorial, we'll add the ability to add, update, and remove items from a shopping list. This means that we'll be working with references and the CKReference class.

We'll also take a closer look at the data model of the shopping list application. How easy is it to make changes to the data model, and how does the application respond to changes we make in the CloudKit Dashboard?

Prerequisites

Remember that I will be using Xcode 7 and Swift 2. If you are using an older version of Xcode, then keep in mind that you are using a different version of the Swift programming language.

In this tutorial, we will continue where we left off in the second tutorial of this series. You can download or clone the project from GitHub.

1. Shopping List Details

Currently, the user can modify the name of a shopping list by tapping the detail disclosure indicator, but the user should also be able to see the contents of a shopping list by tapping one in the lists view controller. To make this work, we first need a new UIViewController subclass.

Step 1: Creating ListViewController

The ListViewController class will display the contents of a shopping list in a table view. The interface of the ListViewController class looks similar to that of the ListsViewController class. We import the CloudKit and SVProgressHUD frameworks and conform the class to the UITableViewDataSource and UITableViewDelegate protocols. Because we'll be using a table view, we declare a constant, ItemCell, that will serve as a cell reuse identifier.

We declare three outlets: messageLabel of type UILabel!tableView of type UITableView!, and activityIndicatorView of type UIActivityIndicatorView!. The list view controller keeps a reference to the shopping list it is displaying in the list property, which is of type CKRecord!. The items in the shopping list are stored in the items property, which is of type [CKRecord]. Finally, we use a helper variable, selection, to keep track of which item in the shopping list the user has selected. This will become clear later in this tutorial.

Step 2: Creating the User Interface

Open Main.storyboard, add a view controller, and set its class to ListViewController in the Identity Inspector. Select the prototype cell of the lists view controller, press the Control key, and drag from the prototype cell to the list view controller. Choose Show from the menu that pops up, and set the identifier to List in the Attributes Inspector.

Add a table view, a label, and an activity indicator view to the view controller's view. Don't forget to wire up the outlets of the view controller as well as those of the table view.

Select the table view and set Prototype Cells to 1 in the Attributes Inspector. Select the prototype cell, and set Style to Right Detail, Identifier to ItemCell, and Accessory to Disclosure Indicator. This is what the view controller should look like when you're finished.

List View Controller

Step 3: Configuring the View Controller

Before we revisit the CloudKit framework, we need to prepare the view controller for the data it's going to receive. Start by updating the implementation of viewDidLoad. We set the view controller's title to the name of the shopping list and invoke two helper methods, setupView and fetchItems.

The setupView method is identical to the one we implemented in the ListsViewController class.

While we're at it, let's also implement another familiar helper method, updateView. In updateView, we update the user interface of the view controller based on the items stored in the items property.

I'm going to leave fetchItems empty for now. We'll revisit this method once we're finished setting up the list view controller.

Step 4: Table View Data Source Methods

We're almost ready to take the application for another test run. Before we do, we need to implement the UITableViewDataSource protocol. If you've read the previous installments of this series, then the implementation will look familiar.

Step 5: Handling Selection

To tie everything together, we need to revisit the ListsViewController class. Start by implementing the tableView(_:didSelectRowAtIndexPath:) method of the UITableViewDelegate protocol.

We also need to update prepareForSegue(segue:sender:) to handle the segue we created a few moments ago. This means that we need to add a new case to the switch statement.

To satisfy the compiler, we also need to declare the SegueList constant at the top of ListsViewController.swift.

Build and run the application to see if everything is wired up correctly. Because we haven't implemented the fetchItems method yet, no items will be displayed. That's something we need to fix.

2. Fetching Items

Step 1: Create a Record Type

Before we can fetch items from the CloudKit backend, we need to create a new record type in the CloudKit Dashboard. Navigate to the CloudKit Dashboard, create a new record type, and name it Items. Each item should have a name, so create a new field, set the field name to name, and set the field type to String.

Each item should also know to which shopping list it belongs. That means each item needs a reference to its shopping list. Create a new field, set the field name to list, and set the field type to Reference. The Reference field type was designed for this exact purpose, managing relationships.

Item Record Type

Head back to Xcode, open ListsViewController.swift, and declare a new constant at the top for the Items record type.

Step 2: Fetching Items

Open ListViewController.swift and navigate to the fetchItems method. The implementation is similar to the fetchLists method of the ListsViewController class. There is an important difference, though.

The difference between fetchItems and fetchLists is the predicate we pass to the CKQuery initializer. We're not interested in every item in the user's private database. We're only interested in the items that are associated with a particular shopping list. This is reflected in the predicate of the CKQuery instance.

We create the predicate by passing in a CKReference instance, which we create by invoking init(recordID:action:). This method accepts two arguments: a CKRecordID instance that references the shopping list record and a CKReferenceAction instance that determines what happens when the shopping list is deleted.

Reference actions are very similar to delete rules in Core Data. If the referenced object (the shopping list in this example) is deleted, then the CloudKit framework inspects the reference action to determine what should happen to the records that hold a reference to the deleted record. The CKReferenceAction enum has two member values:

  • None: If the reference is deleted, nothing happens to the records referencing the deleted record.
  • DeleteSelf: If the reference is deleted, every record referencing the deleted record is also deleted.

Because no item should exist without a shopping list, we set the reference action to DeleteSelf.

The processResponseForQuery(records:error:) method contains nothing new. We process the response of the query and update the user interface accordingly.

Build and run the application. You won't see any items yet, but the user interface should update to reflect that the shopping list is empty.

3. Adding Items

Step 1: Creating AddItemViewController

It's time to implement the ability to add items to a shopping list. Start by creating a new UIViewController subclass, AddItemViewController. The interface of the view controller is similar to that of the AddListViewController class.

At the top, we import the CloudKit and SVProgressHUD frameworks. We declare the AddItemViewControllerDelegate protocol, which will serve the same purpose as the AddListViewControllerDelegate protocol. The protocol defines two methods, one for adding items and one for updating items.

We declare two outlets, a text field and a bar button item. We also declare a property for the delegate and a helper variable, newItem, that helps us determine whether we're creating a new item or updating an existing item. Finally, we declare a property list for referencing the shopping list to which the item will be added and a property item for the item we're creating or updating.

Before we create the user interface, let's implement two actions that we'll need in the storyboard, cancel(_:) and save(_:). We'll update the implementation of the save(_:) action later in this tutorial.

Step 2: Creating the User Interface

Open Main.storyboard, add a bar button item to the navigation bar of the list view controller, and set System Item to Add in the Attributes Inspector. Drag a view controller from the Object Library and set its class to AddItemViewController. Create a segue from the bar button item we just created to the add item view controller. Choose Show from the menu that pops up, and set the segue's identifier to ItemDetail.

Add two bar button items to the navigation bar of the add item view controller, a cancel button on the left and a save button on the right. Connect each bar button item to its corresponding action. Add a text field to the view controller's view and don't forget to connect the outlets of the view controller. This is what the add item view controller should look like when you're finished.

Add Item View Controller

Step 3: Configuring the View Controller

The implementation of the add item view controller contains nothing that we haven't covered yet. There's one exception, though, which we'll discuss in a moment. Let's start by configuring the view controller in viewDidLoad.

We invoke setupView, a helper method, and update the value of newItem. If the item property is equal to nilnewItem is equal to true. This helps us determine whether we're creating or updating a shopping list item.

We also add the view controller as an observer for notifications of type UITextFieldTextDidChangeNotification. This means that the view controller is notified when the contents of the nameTextField change.

In viewDidAppear(animated:), we show the keyboard by calling becomeFirstResponder on nameTextField.

The setupView method invokes two helper methods, updateNameTextField and updateSaveButton. The implementation of these helper methods is straightforward. In updateNameTextField, we populate the text field. In updateSaveButton, we enable or disable the save button based on the contents of the text field.

Before we take a look at the updated implementation of the save(_:) method, we need to implement the textFieldDidChange(_:) method. All we do is invoke updateSaveButton to enable or disable the save button.

Step 4: Saving Items

The save(_:) method is the most interesting method of the AddItemViewController class, because it shows us how to work with CloudKit references. Take a look at the implementation of the save(_:) method below.

Most of its implementation should look familiar since we covered saving records in the AddListViewController class. What interests us most is how the item keeps a reference to its shopping list. We first create a CKReference instance by invoking the designated initializer, init(recordID:action:). We covered the details of creating a CKReference instance a few minutes ago when we created the query for fetching shopping list items.

Telling the item about this reference is easy. We invoke setObjec(_:forKey:) on the item property, passing in the CKReference instance as the value and "list" as the key. The key corresponds to the field name we assigned in the CloudKit Dashboard. Saving the item to iCloud is identical to what we've covered before. That's how easy it is to work with CloudKit references.

The implementation of processResponse(record:error:) contains nothing new. We check to see if any errors popped up and, if no errors were thrown, we notify the delegate.

Step 5: Updating ListViewController

We still have some work to do in the ListViewController class. Start by conforming the ListViewController class to the AddItemViewControllerDelegate protocol. This is also a good moment to declare a constant for the segue with the identifier ItemDetail.

Implementing the AddItemViewControllerDelegate protocol is trivial. In controller(_:didAddItem:), we add the new item to items, sort items, reload the table view, and invoke updateView.

The implementation of controller(_:didUpdateItem:) is even easier. We sort items and reload the table view.

In sortItems, we sort the array of CKRecord instances by name using the sortInPlace function, a method of the MutableCollectionType protocol.

There are two more features we need to implement: updating and deleting shopping list items.

Step 6: Deleting Items

To delete items, we need to implement tableView(_:commitEditingStyle:forRowAtIndexPath:) of the UITableViewDataSource protocol. We fetch the shopping list item that needs to be deleted and pass it to the deleteRecord(_:) method.

The implementation of deleteRecord(_:) doesn't contain anything new. We invoke deleteRecordWithID(_:completionHandler:) on the private database and process the response in the completion handler.

In processResponseForDeleteRequest(record:recordID:error:), we update the items property and the user interface. If something went wrong, we notify the user by showing an alert.

Step 7: Updating Items

The user can update an item by tapping the detail disclosure indicator. This means we need to implement the tableView(_:accessoryButtonTappedForRowWithIndexPath:) delegate method. In this method, we store the user's selection and manually perform the ListDetail segue. Note that nothing happens in the tableView(_:didSelectRowAtIndexPath:) method. All we do is deselect the row the user tapped.

In prepareForSegue(_:sender:), we fetch the shopping list item using the value of the selection property and configure the destination view controller, an instance of the AddItemViewController class.

That's all we need to do to delete and update shopping list items. In the next section, we explore how easy it is to update the data model in the CloudKit Dashboard.

4. Updating the Data Model

If you've ever worked with Core Data, then you know that updating the data model should be done with caution. You need to make sure you don't break anything or corrupt any of the application's persistent stores. CloudKit is a bit more flexible.

The Items record type currently has two fields, name and list. I want to show you what it involves to update the data model by adding a new field. Open the CloudKit Dashboard and add a new field to the Items record. Set field name to number and set the field type to Int(64). Don't forget to save your changes.

Update Item Record Type

Let's now add the ability to modify an item's number. Open AddItemViewController.swift and declare two outlets, a label and a stepper.

We also need to add an action that is triggered when the stepper's value changes. In numberDidChange(_:), we update the contents of numberLabel.

Open Main.storyboard and add a label and a stepper to the add item view controller. Connect the outlets of the view controller to the corresponding user interface elements and connect the numberDidChange(_:) action to the stepper for the Value Changed event.

Update Add Item View Controller

The save(_:) action of the AddItemViewController class also changes slightly. Let's see what that looks like.

We only need to add two lines of code. At the top, we store the value of the stepper in a constant, number. When we configure item, we set number as the value for the "number" key, and that's all there is to it.

We also need to implement a helper method to update the user interface of the add item view controller. The updateNumberStepper method checks if the record has a field named number and updates the stepper if it does.

We invoke updateNumberStepper in the setupView method of the AddItemViewController class.

To visualize the number of each item, we need to make one change to the ListViewController. In tableView(_:cellForRowAtIndexPath:), we set the contents of the cell's right label to the value of the item's number field.

That's all we need to do to implement the changes we made to the data model. There's no need to perform a migration or anything like that. CloudKit takes care of the nitty gritty details.

Conclusion

You should now have a proper foundation in the CloudKit framework. I hope you agree that Apple has done a great job with this framework and the CloudKit Dashboard. There's a lot that we haven't covered in this series, but by now you've learned enough to jump in and get started with CloudKit in your own projects.

If you have any questions or comments, feel free to leave them in the comments below or reach out to me on Twitter.

2018-06-07T13:33:57.000Z2018-06-07T13:33:57.000ZDoron Katz

Keys, Credentials and Storage on Android

$
0
0

In the previous post on Android user data security, we looked at encrypting data via a user-supplied passcode. This tutorial will shift the focus to credential and key storage. I'll begin by introducing account credentials and end with an example of protecting data using the KeyStore.

Often when working with a third-party service there will be some form of authentication required. This may be as simple as a /login endpoint that accepts a username and password. It would seem at first that a simple solution is to build UI that asks the user to log in, then capture and store their login credentials. However, this isn't the best practice because our app shouldn't need to know the credentials for a 3rd party account. Instead, we can use the Account Manager, which delegates handling that sensitive information for us.

Account Manager

The Account Manager is a centralized helper for user account credentials so that your app does not have to deal with passwords directly. It often provides a token in place of the real username and password that can be used to make authenticated requests to a service. An example is when requesting an OAuth2 token. Sometimes all the required information is already stored on the device, and other times the Account Manager will need to call a server for a refreshed token. You may have seen the Accounts section in your device's Settings for various apps. We can get that list of available accounts like this:


The code will require the android.permission.GET_ACCOUNTS permission. If you're looking for a specific account, you can find it like this:

Once you have the account, a token for the account can be retrieved by calling the getAuthToken(Account, String, Bundle, Activity, AccountManagerCallback, Handler) method. The token can then be used to make authenticated API requests to a service. This could be a RESTful API where you pass in a token parameter during an HTTPS request, without having to ever know the user's private account details.

Because each service will have a different way of authenticating and storing the private credentials, the Account Manager provides authenticator modules for a 3rd party service to implement. While Android has implementations for many popular services, it means you can write your own authenticator to handle your app's account authentication and credential storage. This allows you to make sure the credentials are encrypted. Keep in mind, this also means that credentials in the Account Manager that are used by other services may be stored in clear text, making them visible to anyone who has rooted their device.

Instead of simple credentials, there are times when you will need to deal with a key or a certificate for an individual or entity, for example, when a third party sends you a certificate file which you need to keep. The most common scenario is when an app needs to authenticate to a private organization's server. In the next tutorial, we will be looking at using certificates for authentication and secure communications, but I still want to address how to store these items in the meantime. The Keychain API was originally built for that very specific use—installing a private key or certificate pair from a PKCS#12 file.

The Keychain

Introduced in Android 4.0 (API Level 14), the Keychain API deals with key management. Specifically, it works with PrivateKey andX509Certificate objects and provides a more secure container than using your app's data storage. That's because permissions for private keys only allow for your own app to access the keys, and only after user authorization. This means that a lock screen must be set up on the device before you can make use of the credential storage. Also, the objects in the keychain may be bound to secure hardware, if available. The code to install a certificate is as follows:


The user will be prompted for a password to access the private key and an option to name the certificate. To retrieve the key, the following code presents UI that lets the user choose from the list of installed keys.

Once the choice is made, a string alias name is returned in the alias(final String alias) callback where you can access the private key or certificate chain directly.

Armed with that knowledge, let's now see how we can use the credential storage to save your own sensitive data.

The KeyStore

In the previous tutorial, we looked at protecting data via a user-supplied passcode. This kind of setup is good, but app requirements often steer away from having users login each time and remember an additional passcode. That's where the KeyStore API can be used. Since API 1, the KeyStore has been used by the system to store WIFI and VPN credentials. As of 4.3 (API 18), it allows working with your own app-specific asymmetric keys, and in Android M (API 23) it can store an AESsymmetric key. So while the API doesn't allow storing sensitive strings directly, these keys can be stored, and then used to encrypt strings. 

The benefit to storing a key in the KeyStore is that it allows keys to be operated on without exposing the secret content of that key; key data does not enter the app space. Remember that keys are protected by permissions so that only your app can access them, and they may additionally be secure hardware-backed if the device is capable. This creates a container that makes it more difficult to extract keys from a device. 

Generate a New Random Key

So for this example, instead of generating an AES key from a user-supplied passcode, we can auto-generate a random key that will be protected in the KeyStore. We can do this by creating a KeyGenerator instance, set to the "AndroidKeyStore" provider.

Important parts to look at here are the .setUserAuthenticationRequired(true) and .setUserAuthenticationValidityDurationSeconds(120) specifications. These require a lock screen to be set up and lock the key until the user has authenticated. Looking at the documentation for .setUserAuthenticationValidityDurationSeconds(), you will see that it means the key is only available a certain number of seconds from password authentication, and that passing in -1 requires finger print authentication every time you want to access the key. Enabling the requirement for authentication also has the effect of revoking the key when the user removes or changes the lock screen. Because storing an unprotected key along side the encrypted data is like putting a house key under the doormat, these options attempt to protect the key at rest in the event a device is compromised. An example might be an offline data dump of the device. Without the password being known for the device, that data is rendered useless.

The .setRandomizedEncryptionRequired(true) option enables the requirement that there is enough randomization (a new random IV each time) so that if the exact same data is encrypted a second time around, that encrypted output will still be different. This prevents an attacker from gaining clues about the ciphertext based on feeding in the same data. Another option to note is setUserAuthenticationValidWhileOnBody(boolean remainsValid), which locks the key once the device has detected it is no longer on the person.

Encrypting Data

Now that the key is stored in the KeyStore, we can create a method that encrypts data using the Cipher object, given theSecretKey. It will return a HashMap containing the encrypted data, and a randomized IV that will be needed to decrypt the data. The encrypted data, along with the IV, can then be saved to a file or into the shared preferences.

Decrypting to a Byte Array

For decryption, the reverse is applied. The Cipher object is initialized using the DECRYPT_MODE constant and a decrypted byte[] array is returned.

Testing the Example

We can now test our example!

Using RSA Asymmetric Keys for Older Devices

This is a good solution to store data for versions M and higher, but what if your app supports earlier versions? While AES symmetric keys are not supported under M, RSA asymmetric keys are. That means we can use RSA keys and encryption to accomplish the same thing. The main difference here is that an asymmetric keypair contains two keys, a private and a public key, where the public key encrypts the data and the private key decrypts it. A KeyPairGeneratorSpec is passed into the KeyPairGenerator that is initialized with KEY_ALGORITHM_RSAand the "AndroidKeyStore" provider.

To encrypt, we get the RSAPublicKey from the keypair and use it with theCipher object. 

Decryption is done using the RSAPrivateKey object.

One thing about RSA is that encryption is slower than it is in AES. This is usually fine for small amounts of information such as when you're securing shared preference strings. If you find there is a performance problem encrypting large amounts of data, however, you can instead use this example to encrypt and store just an AES key. Then, use that faster AES encryption that was discussed in theprevious tutorialfor the rest of your data. You can generate a new AES key and convert it to abyte[] array that is compatible with this example.

To get the key back from the bytes, do this:

That was a lot of code! To keep all of the examples simple, I have omitted thorough exception handling. But remember that for your production code, it's not recommended to simply catch all Throwable cases in one catch statement.

Conclusion

This completes the tutorial on working with credentials and keys. Much of the confusion around keys and storage has to do with the evolution of the Android OS, but you can choose which solution to use given the API level your app supports. 

Now that we have covered the best practices for securing data at rest, the next tutorial will focus on securing data in transit. 







2018-06-11T12:27:26.000Z2018-06-11T12:27:26.000ZCollin Stuart

Keys, Credentials and Storage on Android

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-30827

In the previous post on Android user data security, we looked at encrypting data via a user-supplied passcode. This tutorial will shift the focus to credential and key storage. I'll begin by introducing account credentials and end with an example of protecting data using the KeyStore.

Often, when working with a third-party service, there will be some form of authentication required. This may be as simple as a /login endpoint that accepts a username and password. 

It would seem at first that a simple solution is to build a UI that asks the user to log in, and then capture and store their login credentials. However, this isn't the best practice because our app shouldn't need to know the credentials for a third-party account. Instead, we can use the Account Manager, which delegates handling that sensitive information for us.

Account Manager

The Account Manager is a centralized helper for user account credentials so that your app does not have to deal with passwords directly. It often provides a token in place of the real username and password that can be used to make authenticated requests to a service. An example is when requesting an OAuth2 token

Sometimes, all the required information is already stored on the device, and other times the Account Manager will need to call a server for a refreshed token. You may have seen the Accounts section in your device's Settings for various apps. We can get that list of available accounts like this:

The code will require the android.permission.GET_ACCOUNTS permission. If you're looking for a specific account, you can find it like this:

Once you have the account, a token for the account can be retrieved by calling the getAuthToken(Account, String, Bundle, Activity, AccountManagerCallback, Handler) method. The token can then be used to make authenticated API requests to a service. This could be a RESTful API where you pass in a token parameter during an HTTPS request, without ever having to know the user's private account details.

Because each service will have a different way of authenticating and storing the private credentials, the Account Manager provides authenticator modules for a third-party service to implement. While Android has implementations for many popular services, it means you can write your own authenticator to handle your app's account authentication and credential storage. This allows you to make sure the credentials are encrypted. Keep in mind, this also means that credentials in the Account Manager that are used by other services may be stored in clear text, making them visible to anyone who has rooted their device.

Instead of simple credentials, there are times when you will need to deal with a key or a certificate for an individual or entity—for example, when a third party sends you a certificate file which you need to keep. The most common scenario is when an app needs to authenticate to a private organization's server. 

In the next tutorial, we will be looking at using certificates for authentication and secure communications, but I still want to address how to store these items in the meantime. The Keychain API was originally built for that very specific use—installing a private key or certificate pair from a PKCS#12 file.

The Keychain

Introduced in Android 4.0 (API Level 14), the Keychain API deals with key management. Specifically, it works with PrivateKey andX509Certificate objects and provides a more secure container than using your app's data storage. That's because permissions for private keys only allow for your own app to access the keys, and only after user authorization. This means that a lock screen must be set up on the device before you can make use of the credential storage. Also, the objects in the keychain may be bound to secure hardware, if available. 

The code to install a certificate is as follows:

The user will be prompted for a password to access the private key and an option to name the certificate. To retrieve the key, the following code presents a UI that lets the user choose from the list of installed keys.

Once the choice is made, a string alias name is returned in the alias(final String alias) callback where you can access the private key or certificate chain directly.

Armed with that knowledge, let's now see how we can use the credential storage to save your own sensitive data.

The KeyStore

In the previous tutorial, we looked at protecting data via a user-supplied passcode. This kind of setup is good, but app requirements often steer away from having users log in each time and remember an additional passcode. 

That's where the KeyStore API can be used. Since API 1, the KeyStore has been used by the system to store WiFi and VPN credentials. As of 4.3 (API 18), it allows you to work with your own app-specific asymmetric keys, and in Android M (API 23) it can store an AESsymmetric key. So while the API doesn't allow storing sensitive strings directly, these keys can be stored and then used to encrypt strings. 

The benefit to storing a key in the KeyStore is that it allows keys to be operated on without exposing the secret content of that key; key data does not enter the app space. Remember that keys are protected by permissions so that only your app can access them, and they may additionally be secure hardware-backed if the device is capable. This creates a container that makes it more difficult to extract keys from a device. 

Generate a New Random Key

For this example, instead of generating an AES key from a user-supplied passcode, we can auto-generate a random key that will be protected in the KeyStore. We can do this by creating a KeyGenerator instance, set to the "AndroidKeyStore" provider.

Important parts to look at here are the .setUserAuthenticationRequired(true) and .setUserAuthenticationValidityDurationSeconds(120) specifications. These require a lock screen to be set up and the key to be locked until the user has authenticated. 

Looking at the documentation for .setUserAuthenticationValidityDurationSeconds(), you will see that it means the key is only available a certain number of seconds from password authentication, and that passing in -1 requires fingerprint authentication every time you want to access the key. Enabling the requirement for authentication also has the effect of revoking the key when the user removes or changes the lock screen. 

Because storing an unprotected key alongside the encrypted data is like putting a house key under the doormat, these options attempt to protect the key at rest in the event a device is compromised. An example might be an offline data dump of the device. Without the password being known for the device, that data is rendered useless.

The .setRandomizedEncryptionRequired(true) option enables the requirement that there is enough randomization (a new random IV each time) so that if the same data is encrypted a second time around, that encrypted output will still be different. This prevents an attacker from gaining clues about the ciphertext based on feeding in the same data. 

Another option to note is setUserAuthenticationValidWhileOnBody(boolean remainsValid), which locks the key once the device has detected it is no longer on the person.

Encrypting Data

Now that the key is stored in the KeyStore, we can create a method that encrypts data using the Cipher object, given theSecretKey. It will return a HashMap containing the encrypted data and a randomized IV that will be needed to decrypt the data. The encrypted data, along with the IV, can then be saved to a file or into the shared preferences.

Decrypting to a Byte Array

For decryption, the reverse is applied. The Cipher object is initialized using the DECRYPT_MODE constant, and a decrypted byte[] array is returned.

Testing the Example

We can now test our example!

Using RSA Asymmetric Keys for Older Devices

This is a good solution to store data for versions M and higher, but what if your app supports earlier versions? While AES symmetric keys are not supported under M, RSA asymmetric keys are. That means we can use RSA keys and encryption to accomplish the same thing. 

The main difference here is that an asymmetric keypair contains two keys, a private and a public key, where the public key encrypts the data and the private key decrypts it. A KeyPairGeneratorSpec is passed into the KeyPairGenerator that is initialized with KEY_ALGORITHM_RSAand the "AndroidKeyStore" provider.

To encrypt, we get the RSAPublicKey from the keypair and use it with theCipher object. 

Decryption is done using the RSAPrivateKey object.

One thing about RSA is that encryption is slower than it is in AES. This is usually fine for small amounts of information, such as when you're securing shared preference strings. If you find there is a performance problem encrypting large amounts of data, however, you can instead use this example to encrypt and store just an AES key. Then, use that faster AES encryption that was discussed in theprevious tutorial for the rest of your data. You can generate a new AES key and convert it to abyte[] array that is compatible with this example.

To get the key back from the bytes, do this:

That was a lot of code! To keep all of the examples simple, I have omitted thorough exception handling. But remember that for your production code, it's not recommended to simply catch all Throwable cases in one catch statement.

Conclusion

This completes the tutorial on working with credentials and keys. Much of the confusion around keys and storage has to do with the evolution of the Android OS, but you can choose which solution to use given the API level your app supports. 

Now that we have covered the best practices for securing data at rest, the next tutorial will focus on securing data in transit. 

2018-06-11T12:27:26.000Z2018-06-11T12:27:26.000ZCollin Stuart

How to Use Free 3D Models From Google Poly in Android Apps

$
0
0

There is a huge demand these days for Android apps that offer immersive virtual reality or augmented reality experiences. As a developer, there are many different frameworks you can use to create such apps. 

But, unless you are also a skilled 3D artist, how are you going to create the 3D objects you would be displaying in those apps? Are you ready to spend months learning how to work with 3D modeling programs such as Blender or Maya? If you are not, you should consider using Google Poly, an online repository containing thousands of 3D assets that come with Creative Commons licenses.

Most of the assets you can find on Poly today are low poly with simple materials. This is because the average mobile GPU is yet to become powerful enough to display 3D objects with high polygon counts in real time.

In this tutorial, I'll introduce you to the Poly API. I'll also show you how to use Processing for Android to render the 3D assets you download.

Prerequisites

To make the most of this tutorial, you'll need:

1. Acquiring an API Key

All the HTTP requests you make to the Poly API must be accompanied by an API key that belongs to you. To acquire the key, start by logging in to the Google Cloud console and navigating to the APIs dashboard.

APIs dashboard on Cloud console

Next, press the Enable APIs and services button, expand the Other category, and select Poly API.

Other APIs section

You can now press the Enable button to enable the Poly API.

Poly API screen

Once the API is enabled, a set of API keys are generated for it automatically. You can open the Credentials tab to take a look at them.

Credentials page

For this tutorial, you'll be needing only the Android key. Make a note of it so you can use it later.

2. Project Setup

Because Poly currently doesn't have an official toolkit for the Android platform, you'll have to work with the Poly API directly using its REST interface. By using the Fuel networking library, which is optimized for the Kotlin language, you can save a lot of time and effort. So add the following implementation dependency in the app module's build.gradle file:

To be able to display the 3D assets you download from the Poly repository, you'll also need a rendering engine. Processing for Android comes with one, so add it as another dependency.

Lastly, don't forget to request the INTERNET permission in the manifest file of your project.

3. Listing Assets

To be able to download a Poly asset, you must know its unique ID. By using a browser, one that supports WebGL, you can easily determine the ID of any asset. It's right in the address bar.

Poly asset ID shown in the address bar

However, if you want to allow your users to dynamically, at run time, decide which assets they want to use, you can use the assets.list REST method to determine the IDs of those assets. The method allows you to look for assets using a variety of parameters, such as keywords, categories, and 3D file formats.

For the sake of a realistic example, let's now try to find the IDs of a few assets that belong to the animals category. You are, of course, free to choose any other valid category, such as architecture, food, or people.

Before you compose your HTTP request, it's a good idea to declare your API key and the base URL of the Poly API as constants inside your activity.

Using the base URL, you can build the URL of the assets.list REST method as shown below:

At this point, you can create a valid HTTP GET request by calling the httpGet() method and passing your API key and the desired category as query parameters to it. Optionally, you can use the format query parameter to specify the desired format of the assets. Poly supports OBJ, FBX, TILT, and several other popular 3D formats.

Because the method runs asynchronously and its result is a JSON document, you must attach an event handler to it by using the responseJSON() method. The following code shows you how:

Inside the event handler, if your request was successful, you'll have access to a list of Asset objects. The name field of each such object specifies its ID.

Additionally, each object will have fields such as displayName, license, and authorName, which you might find useful. For now, let's simply print the name and displayName of all the objects. The following code shows you how:

If you run your app now, you should be able to see the following output in the Logcat window of Android Studio.

Logcat window showing asset names and IDs

4. Downloading Assets

Once you have the unique ID of an asset, you can directly append it to the base URL of the Poly API to create an asset URL.

When you make an HTTP GET request to the asset URL using the httpGet() method again, you'll get a JSON document containing just one Asset object.

As you may have noticed in the above code, this request too must have a query parameter mentioning your API key.

You've already learned how to use some of the fields present in the Asset object in the previous step. Now, all you need to do is use the formats array present in the object to determine the URLs and names of the files associated with the asset. Each item in the array will have three important fields: 

  • formatType, which lets you determine the type of the asset
  • root, which contains the name and URL of the primary file associated with the asset
  • resources, which contains details about all the secondary files associated with the asset, such as materials and textures

If you're working with the OBJ format, the primary file will be a .obj file containing vertices and faces data, and the secondary files will usually be .mtl files containing data about the materials used. The following code shows you how to determine the URLs of both the primary and secondary files:

In the above code, in addition to the URL of the .mtl file, we're also determining its name using the relativePath field. Doing so is important because the name is hard coded into the mtllib element of the .obj file and should not be changed.

Once you have the URLs of both the files, you can use the httpDownload() method of the Fuel library to download them. Here's how you can download them to your app's private storage directory, whose absolute path can be determined using the filesDir property:

5. Displaying Assets

You'll need a 3D canvas to draw the Poly asset you downloaded. To create one, you must extend the PApplet class offered by the Processing for Android library. However, a canvas created this way will, by default, support only 2D shapes. To configure it to draw 3D shapes as well, override the settings() method and pass P3D as an argument to the fullScreen() method, which also makes the canvas as large as the user's screen.

Next, create a new property inside the class to represent the Poly asset as a PShape object.

To initialize the property, override the setup() method and call the loadShape() method, passing the absolute path of the .obj file you downloaded as an argument to it.

You can now start drawing on the canvas by overriding the draw() method. Inside the method, the first thing you need to do is call the background() method to ensure that you are always drawing on a blank canvas.

When drawn directly, most Poly assets look very small and inverted. You can fix this either by using a custom camera or by using canvas transformations. To keep this tutorial simple and intuitive, let's use canvas transformations.

To increase the size of the asset, use the scale() method and pass a large negative value to it. The value must be negative to make sure that the asset is flipped vertically. Optionally, you can use the translate() method to adjust its position along the X and Y axes. The following code shows you how:

You can now go ahead and draw the asset by calling the shape() method.

The canvas is currently not a part of your activity's view hierarchy. Therefore, if you try running your app now, you won't be able to see the asset. To fix this, first add a new FrameLayout widget to the activity's layout XML file.

Then, create a new PFragment instance using the canvas and point it to the FrameLayout widget.

At this point, you can run the app again to see the asset.

App showing Poly asset

Conclusion

You now know how to use the Poly API to search for and download 3D assets. In this tutorial, you also learned how to render and manipulate those assets using Processing for Android.

It's worth noting that many of the assets available on Poly were created using Google Blocks, an application available for users of HTC Vive and Oculus Rift. If you own those VR headsets, do consider creating and submitting your own models.

To learn more about the Poly API, you can refer to the official documentation.

2018-06-25T17:00:00.000Z2018-06-25T17:00:00.000ZAshraff Hathibelagal

How to Use Free 3D Models From Google Poly in Android Apps

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31356

There is a huge demand these days for Android apps that offer immersive virtual reality or augmented reality experiences. As a developer, there are many different frameworks you can use to create such apps. 

But, unless you are also a skilled 3D artist, how are you going to create the 3D objects you would be displaying in those apps? Are you ready to spend months learning how to work with 3D modeling programs such as Blender or Maya? If you are not, you should consider using Google Poly, an online repository containing thousands of 3D assets that come with Creative Commons licenses.

Most of the assets you can find on Poly today are low poly with simple materials. This is because the average mobile GPU is yet to become powerful enough to display 3D objects with high polygon counts in real time.

In this tutorial, I'll introduce you to the Poly API. I'll also show you how to use Processing for Android to render the 3D assets you download.

Prerequisites

To make the most of this tutorial, you'll need:

1. Acquiring an API Key

All the HTTP requests you make to the Poly API must be accompanied by an API key that belongs to you. To acquire the key, start by logging in to the Google Cloud console and navigating to the APIs dashboard.

APIs dashboard on Cloud console

Next, press the Enable APIs and services button, expand the Other category, and select Poly API.

Other APIs section

You can now press the Enable button to enable the Poly API.

Poly API screen

Once the API is enabled, a set of API keys are generated for it automatically. You can open the Credentials tab to take a look at them.

Credentials page

For this tutorial, you'll be needing only the Android key. Make a note of it so you can use it later.

2. Project Setup

Because Poly currently doesn't have an official toolkit for the Android platform, you'll have to work with the Poly API directly using its REST interface. By using the Fuel networking library, which is optimized for the Kotlin language, you can save a lot of time and effort. So add the following implementation dependency in the app module's build.gradle file:

To be able to display the 3D assets you download from the Poly repository, you'll also need a rendering engine. Processing for Android comes with one, so add it as another dependency.

Lastly, don't forget to request the INTERNET permission in the manifest file of your project.

3. Listing Assets

To be able to download a Poly asset, you must know its unique ID. By using a browser, one that supports WebGL, you can easily determine the ID of any asset. It's right in the address bar.

Poly asset ID shown in the address bar

However, if you want to allow your users to dynamically, at run time, decide which assets they want to use, you can use the assets.list REST method to determine the IDs of those assets. The method allows you to look for assets using a variety of parameters, such as keywords, categories, and 3D file formats.

For the sake of a realistic example, let's now try to find the IDs of a few assets that belong to the animals category. You are, of course, free to choose any other valid category, such as architecture, food, or people.

Before you compose your HTTP request, it's a good idea to declare your API key and the base URL of the Poly API as constants inside your activity.

Using the base URL, you can build the URL of the assets.list REST method as shown below:

At this point, you can create a valid HTTP GET request by calling the httpGet() method and passing your API key and the desired category as query parameters to it. Optionally, you can use the format query parameter to specify the desired format of the assets. Poly supports OBJ, FBX, TILT, and several other popular 3D formats.

Because the method runs asynchronously and its result is a JSON document, you must attach an event handler to it by using the responseJSON() method. The following code shows you how:

Inside the event handler, if your request was successful, you'll have access to a list of Asset objects. The name field of each such object specifies its ID.

Additionally, each object will have fields such as displayName, license, and authorName, which you might find useful. For now, let's simply print the name and displayName of all the objects. The following code shows you how:

If you run your app now, you should be able to see the following output in the Logcat window of Android Studio.

Logcat window showing asset names and IDs

4. Downloading Assets

Once you have the unique ID of an asset, you can directly append it to the base URL of the Poly API to create an asset URL.

When you make an HTTP GET request to the asset URL using the httpGet() method again, you'll get a JSON document containing just one Asset object.

As you may have noticed in the above code, this request too must have a query parameter mentioning your API key.

You've already learned how to use some of the fields present in the Asset object in the previous step. Now, all you need to do is use the formats array present in the object to determine the URLs and names of the files associated with the asset. Each item in the array will have three important fields: 

  • formatType, which lets you determine the type of the asset
  • root, which contains the name and URL of the primary file associated with the asset
  • resources, which contains details about all the secondary files associated with the asset, such as materials and textures

If you're working with the OBJ format, the primary file will be a .obj file containing vertices and faces data, and the secondary files will usually be .mtl files containing data about the materials used. The following code shows you how to determine the URLs of both the primary and secondary files:

In the above code, in addition to the URL of the .mtl file, we're also determining its name using the relativePath field. Doing so is important because the name is hard coded into the mtllib element of the .obj file and should not be changed.

Once you have the URLs of both the files, you can use the httpDownload() method of the Fuel library to download them. Here's how you can download them to your app's private storage directory, whose absolute path can be determined using the filesDir property:

5. Displaying Assets

You'll need a 3D canvas to draw the Poly asset you downloaded. To create one, you must extend the PApplet class offered by the Processing for Android library. However, a canvas created this way will, by default, support only 2D shapes. To configure it to draw 3D shapes as well, override the settings() method and pass P3D as an argument to the fullScreen() method, which also makes the canvas as large as the user's screen.

Next, create a new property inside the class to represent the Poly asset as a PShape object.

To initialize the property, override the setup() method and call the loadShape() method, passing the absolute path of the .obj file you downloaded as an argument to it.

You can now start drawing on the canvas by overriding the draw() method. Inside the method, the first thing you need to do is call the background() method to ensure that you are always drawing on a blank canvas.

When drawn directly, most Poly assets look very small and inverted. You can fix this either by using a custom camera or by using canvas transformations. To keep this tutorial simple and intuitive, let's use canvas transformations.

To increase the size of the asset, use the scale() method and pass a large negative value to it. The value must be negative to make sure that the asset is flipped vertically. Optionally, you can use the translate() method to adjust its position along the X and Y axes. The following code shows you how:

You can now go ahead and draw the asset by calling the shape() method.

The canvas is currently not a part of your activity's view hierarchy. Therefore, if you try running your app now, you won't be able to see the asset. To fix this, first add a new FrameLayout widget to the activity's layout XML file.

Then, create a new PFragment instance using the canvas and point it to the FrameLayout widget.

At this point, you can run the app again to see the asset.

App showing Poly asset

Conclusion

You now know how to use the Poly API to search for and download 3D assets. In this tutorial, you also learned how to render and manipulate those assets using Processing for Android.

It's worth noting that many of the assets available on Poly were created using Google Blocks, an application available for users of HTC Vive and Oculus Rift. If you own those VR headsets, do consider creating and submitting your own models.

To learn more about the Poly API, you can refer to the official documentation.

2018-06-25T17:00:00.000Z2018-06-25T17:00:00.000ZAshraff Hathibelagal

10 Best Ionic 3 App Templates

$
0
0

Ionic 3 is the latest version of the popular HTML5 mobile app development framework targeted at building hybrid mobile apps.

Unlike native apps designed to work either with iOS or Android systems, a hybrid app is a small website running in a browser shell within an app that has access to the phone’s native system. Hybrid apps have many benefits over pure native apps in terms of platform support, speed of development, and access to 3rd party code.

Today I take a look at the 10 best Ionic 3 app templates available at CodeCanyon

1. Ionic 3 UI Theme

Developers of Ionic 3 UI Theme  promise that you can make just about any app with their UI app template. With over 70 layouts  and hundreds of HTML5 UI components they might just be right. Apart from offering maximum flexibility and easy customisation the app offers Google Analytics so you can track your user’s behaviour, MailChimp integration, Google Maps integration and so much more. 

Ionic 3 UI Theme

User Aligorkem says:

“I believe this is one of the nicest Ionic3 template in the market. The developer is also very responsive to support emails.”

2. Car Pooling IONIC 3

Car Pooling IONIC 3 app template targets developers interested in creating a carpooling app for clients. The premise of the app is to allow car owners to offer rides to people who use the same route as them, allowing them to earn cash while driving their normal routes to work, school, etc. 

Car Pooling IONIC 3

The app allows car owners to add the start and end location of their route, and the days and time they drive their route.  Potential passengers then send a request for a ride which the car owner can decline or accept. There’s also a chat feature which allows car owners and potential passengers to chat directly to resolve questions.

3. Ionic 3 App for WooCommerce

With Ionic 3 App for WooCommerce you can create your own WooCommerce mobile app for Android, iOS and Windows platforms. The app will allow users to connect to their app stores and sync categories and products in real-time and promises that your customers a easy and hassle-free shopping experience. 

The app template supports 99% of payment methods out there, automatically loads shipping methods, allows customers to search products globally on the home page as well as search  products within categories and much more. 

Ionic 3 App for WooCommerce

User Darklink000 says:

“All the promised functions are present and work correctly, I was able to publish my app on Android and App store without major problems, clear documentation. Excellent product.”

4. Yoga Guide 

One of the newest apps on CodeCanyon, Yoga Guide app template is perfect for developers working in the health and fitness market. The app is designed to help end-users practice yoga at their own pace and in the comfort of their own home or office. The app is easy to customise and has a clean and modern design which will allows end-users to navigate around the app easily.  

Yoga Guide

Some of the templates great features include a sign-up and sign-in screen, profile page, list of yoga poses with explanations, ability to set reminder alarms, ability to save poses to favourites category and more. 

5. Firetask

If you’re looking for an Ionic 3 app template to build a social media app for yourself or a client, look no further. Firetask is a social media app template that features such advanced functions as social login, offline sync with Firebase, account management, and more.

Firetask

User Rdrpart says:

"Great template to start an application, well modulated, and the code is well documented and the support is 10 Stars."

6. IonFullApp

IonFullApp  is a multipurpose app template which offers more than 34 useful components. The template comes in three different versions which offer various functions and screens to suit different needs.

IonFullApp

7. Ionic 3 Restaurant

Built with Ionic 3, Angular 5, Typescript and SASS, the Ionic 3 Restaurant app template is designed to help you build apps for restaurants, bakery, coffee shop and any other food or commerce related venture.

The app provides a good range of homepage, registration and login page layouts as well as other features, like categories, an orders page, an offers page, etc. 

Ionic 3 Restaurant

User Hoorida says:

“I used this starter template in some of my projects and found it to be simply one of the best Ionic templates available for any e-commerce store. Another thing I love is their technical support. Their team is very experience in these technologies and helped us to customise this app for multi-restaurant app. 

8. Ionic 3 Toolkit

Ionic 3 Toolkit app template offers developers two advantages. First it lives up to its promise of being a toolkit with its wide range of features and its modular structure, which allow users to build whatever kind of app they need quickly and easily.  

Ionic 3 Toolkit

Secondly, it allows you to collect data from your WordPress, Drupal, YouTube, Vimeo, Instagram and other social media accounts and add them to the content of your app as needed. Furthermore, the template makes it easy to customise the template’s default styles by changing the pre-defined colours or the default value of the SASS.

9. Hotel Room Reservation

Another recent addition to CodeCanyon’s mobile app section, Hotel Room Reservation app template is created in the vein of popular hotel booking services like Booking and AirBnB. 

Hotel Room Reservation

The  template helps developers to create an app that will allow end-users to search, view and book hotels in their targeted location. The app is integrated with Google Maps and PayPal for end-user convenience. 

10. WooCommerce Mobile App 

Owing to the popularity of e-commerce apps, I'll round out my list with another e-commerce app template: WooCommerce Mobile App template. In spite of being on the market for just a few months, this template has been selling steadily and is one of the best rated templates in this category. 

The app allows clients to connects to their Woo Commerce store and sync categories and products in real-time. Once customers register and login, they can shop, pay for items, view order status and order history and manage their account.  Useful features include a featured products page, categories, a powerful search and filter, list and grid views, ratings and reviews, etc. 

WooCommerce Mobile App

User Sheen_An says:

“I love the product - very comprehensive and easy to use. More than that - the support is good with fast responses.”

Conclusion

These 10 best Ionic 3 app templates are just a small selection of the hundreds of Ionic 3 app templates we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills building Ionic apps and templates, then check out some of the ever-so-useful Ionic tutorials we have on offer!

2018-06-27T17:14:44.292Z2018-06-27T17:14:44.292ZNona Blackman

10 Best Ionic 3 App Templates

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31398

Ionic 3 is the latest version of the popular HTML5 mobile app development framework targeted at building hybrid mobile apps.

Unlike native apps designed to work either with iOS or Android systems, a hybrid app is a small website running in a browser shell within an app that has access to the phone’s native system. Hybrid apps have many benefits over pure native apps in terms of platform support, speed of development, and access to third-party code.

Today I take a look at the ten best Ionic 3 app templates available at CodeCanyon

1. Ionic 3 UI Theme

The developers of Ionic 3 UI Theme promise that you can make just about any app with their UI app template. With over 70 layouts and hundreds of HTML5 UI components, they might just be right. Apart from offering maximum flexibility and easy customisation, the app offers Google Analytics so you can track your user’s behaviour, MailChimp integration, Google Maps integration, and so much more. 

Ionic 3 UI Theme

User Aligorkem says:

“I believe this is one of the nicest Ionic3 template in the market. The developer is also very responsive to support emails.”

2. Car Pooling IONIC 3

Car Pooling IONIC 3 app template targets developers interested in creating a carpooling app for clients. The premise of the app is to allow car owners to offer rides to people who use the same route as them, allowing them to earn cash while driving their normal routes to work, school, etc. 

Car Pooling IONIC 3

The app allows car owners to add the start and end location of their route, and the days and time they drive their route. Potential passengers then send a request for a ride, which the car owner can decline or accept. There’s also a chat feature which allows car owners and potential passengers to chat directly to resolve questions.

3. Ionic 3 App for WooCommerce

With Ionic 3 App for WooCommerce, you can create your own WooCommerce mobile app for Android, iOS and Windows platforms. The app will allow users to connect to their app stores and sync categories and products in real time, and it promises your customers an easy and hassle-free shopping experience. 

The app template supports 99% of payment methods out there, automatically loads shipping methods, allows customers to search for products globally on the home page or within categories, and much more. 

Ionic 3 App for WooCommerce

User Darklink000 says:

“All the promised functions are present and work correctly, I was able to publish my app on Android and App store without major problems, clear documentation. Excellent product.”

4. Yoga Guide 

One of the newest apps on CodeCanyon, the Yoga Guide app template is perfect for developers working in the health and fitness market. The app is designed to help end users practice yoga at their own pace and in the comfort of their own home or office. The app is easy to customise and has a clean and modern design which allows end users to navigate around the app easily.  

Yoga Guide

Some of the template's great features include a sign-up and sign-in screen, profile page, list of yoga poses with explanations, ability to set reminder alarms, ability to save poses to a favourites category, and more. 

5. Firetask

If you’re looking for an Ionic 3 app template to build a social media app for yourself or a client, look no further. Firetask is a social media app template that features such advanced functions as social login, offline sync with Firebase, account management, and more.

Firetask

User Rdrpart says:

"Great template to start an application, well modulated, and the code is well documented and the support is 10 Stars."

6. IonFullApp

IonFullApp is a multipurpose app template which offers more than 34 useful components. The template comes in three different versions which offer various functions and screens to suit different needs.

IonFullApp

7. Ionic 3 Restaurant

Built with Ionic 3, Angular 5, Typescript and Sass, the Ionic 3 Restaurant app template is designed to help you build apps for restaurants, bakeries, coffee shops, and any other food or commerce related venture.

The app provides a good range of homepage, registration and login page layouts as well as other features, like categories, an orders page, an offers page, etc. 

Ionic 3 Restaurant

User Hoorida says:

“I used this starter template in some of my projects and found it to be simply one of the best Ionic templates available for any e-commerce store. Another thing I love is their technical support. Their team is very experience in these technologies and helped us to customise this app for multi-restaurant app. 

8. Ionic 3 Toolkit

The Ionic 3 Toolkit app template offers developers two advantages. First, it lives up to its promise of being a toolkit with its wide range of features and its modular structure, which allow users to build whatever kind of app they need quickly and easily.  

Ionic 3 Toolkit

Secondly, it allows you to collect data from your WordPress, Drupal, YouTube, Vimeo, Instagram and other social media accounts and add them to the content of your app as needed. Furthermore, the template makes it easy to customise the template’s default styles by changing the pre-defined colours or the default value of the Sass.

9. Hotel Room Reservation

Another recent addition to CodeCanyon’s mobile app section, the Hotel Room Reservation app template is created in the vein of popular hotel booking services like Booking and AirBnB. 

Hotel Room Reservation

The template helps developers to create an app that will allow end users to search, view and book hotels in their targeted location. The app is integrated with Google Maps and PayPal for user convenience. 

10. WooCommerce Mobile App

Owing to the popularity of e-commerce apps, I'll round out my list with another e-commerce app template: WooCommerce Mobile App template. In spite of being on the market for just a few months, this template has been selling steadily and is one of the best-rated templates in this category. 

The app allows clients to connect to their WooCommerce store and sync categories and products in real time. Once customers register and log in, they can shop, pay for items, view order status and order history, and manage their account. Useful features include a featured products page, categories, a powerful search and filter, list and grid views, ratings and reviews, etc. 

WooCommerce Mobile App

User Sheen_An says:

“I love the product - very comprehensive and easy to use. More than that - the support is good with fast responses.”

Conclusion

These ten best Ionic 3 app templates are just a small selection of the hundreds of Ionic 3 app templates we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills in building Ionic apps and templates, then check out some of the ever-so-useful Ionic tutorials we have on offer!

2018-06-27T17:14:44.292Z2018-06-27T17:14:44.292ZNona Blackman

10 Best iOS App Templates for Business

$
0
0

If you run a business you’re always looking for tools that will enable increased productivity and maximise time and without adding to energy commitments. Happily there are a number of iOS app templates available at CodeCanyon that will help businesses do just that. 

App templates are ideal for businesses and developers targeting the business market because templates provide core functionality and make it easier to create one’s own specialised apps.  

Many beginners use app templates as a learning tool to improve their coding skills, while others choose to upload their new app creations to iTunes for approval and inclusion in the app store.

Today we’ll look at the 10 best iOS app templates for business available at CodeCanyon.

1. Wireless Device Connection

This is the kind of app that is useful for any business person who has ever been in a meeting and wanted to share information on their mobile phone easily. This is the kind of app that users will pay good money to own! 

Wireless Device Connection

Built with Swift, as all the other apps here are, the Wireless Device Connection  app template allows developers to create an app that uses Apple’s Multipeer Connectivity Framework to connect with up to 10 iOS devices at a time. The app lets users share files, images, videos, speeches and text. This makes it a great tool not only for impressing your business colleagues with your tech-savvy, but also for sharing information easily and efficiently. 

2. My Business App

The My Business App template will appeal to small businesses which have a limited technology budget but want to use their website content to create their own app. 

My Business App

The beauty of this template is that it requires no coding knowledge. Using just their website’s URL, in just a few clicks users can convert their website content into an app. The template provides a number of colour themes to match your company’s brand, offers push notification and will work equally well on iPhones and iPads.

3. Topics

Topics is a social media app template that helps developers create a forum type app. This is great for businesses because it allows them to create their own space for customers and clients to chat about issues regarding their products or services. 

Topics

Clients can browse topics or search for them, join existing conversations by posting comments or can create a new topic if it doesn’t already exist. The template also provides report features for inappropriate topics, comments and/or users. This functionality is needed for this type of app in order to pass the submissions review for Apples App Store.

4. KST Chart

Need to create your own chart on the spot in a meeting? KST Chart app template provides an easy to use and customise iOS chart library that business owners will find a handy on-the-go tool.  

KST Chart

The template allows developers to build an app that enables the end-user to create a wide variety of charts including bar, column, line charts etc. quickly and easily. 

5. TODO App

There is a reason organiser apps are popular in the business category. They help busy people with endless demands on their time organise and prioritise tasks and keep on top of their duties large and small. 

TODO App

For businesses who want to create their own organiser app with features and events relevant to their specific company, there is the TODO App template which comes with a number of great features like colour themes to match the company’s brand and various viewing options like a Today task page and a Calendar page. In addition, the app is so easy to set up and customise that it doesn't requires knowledge of coding to get started. 

6. Secure Notes

The Secure Notes app template allows developers to create a notes app that works with Touch ID and PIN technology to ensure that notes the end-user makes on their device are private. 

Secure Notes

This is ideal for business people dealing with sensitive information who may want to make notes on the go but who also want to ensure that what they write stays private. Features include ability to organise notes by category and to add rich text in the notes. 

7. Eventio

The Eventio app template allows developers to create an event app. End-users can create, edit, and delete events and can also create custom categories to organise events. 

Eventio

Events can then be sorted by time, or category. The app provides an animated countdown to events which can be customised with a company’s brand. 

8. Video Survey & Review Tool

The Video Survey & Review Tool app template is ideal for business that want to create a customer survey app that allows customers to give feedback about a product or service. 

Video Survey  Review Tool

Companies are able to create their survey questions using the app and their clients then answer the questionnaire through video via the app. The app template is easy to customise and  features include detailed analytics report and full integration with a cloud service of your choice. 

9. Multi-language Translator

Today many business interact with people across the globe, and for those times when you’re confronted with a speaker of a language you aren’t fluent in, a good translator app is a necessity. 

Multi-language Translator

The Multi-language Translator app template allows developers to create an app that is capable of translating over 200 languages. Aside from the usual language translator, it allows the end-user to translate speech to text and text to speech. Which makes conversation between speakers of different languages not only possible but far more fluid than before. 

10. AskIt

Customer service is one of those aspects of business that can definitely make or break a company and the AskIt app template aims at helping companies make it when it comes to supporting their customers. 

AskIt

The template allows developers to create a specialised question and answer messaging app where clients and customers can message their queries and designated employees can message an answer. What’s more, other customers have access to these questions and answers which helps reduce duplication and saves time. 

Some of the great features available with this app are the ability to search questions using keywords, the ability for users to like questions and answers and the ability to report abusive contents. 

Conclusion

These 10 best iOS app templates for business are just a small selection of the hundreds of  iOS app templates we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills building iOS apps and templates, then check out some of the ever-so-useful iOS tutorials we have on offer!

2018-06-29T12:22:17.000Z2018-06-29T12:22:17.000ZNona Blackman

10 Best iOS App Templates for Business

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31385

If you run a business, you’re always looking for tools that will enable increased productivity and maximise time, without adding to energy commitments. Happily there are a number of iOS app templates available at CodeCanyon that will help businesses do just that. 

App templates are ideal for businesses and developers targeting the business market because the templates provide core functionality and make it easier to create your own specialised apps.  

Many beginners use app templates as a learning tool to improve their coding skills, while others choose to upload their new app creations to iTunes for approval and inclusion in the app store.

Today we’ll look at the 10 best iOS app templates for business available at CodeCanyon.

1. Wireless Device Connection

This is the kind of app that is useful for any business person who has ever been in a meeting and wanted to share information on their mobile phone easily. This is the kind of app that users will pay good money to own! 

Wireless Device Connection

Built with Swift, as all the other apps here are, the Wireless Device Connection app template allows developers to create an app that uses Apple’s Multipeer Connectivity Framework to connect with up to 10 iOS devices at a time. The app lets users share files, images, videos, speeches, and text. This makes it a great tool not only for impressing your business colleagues with your tech savvy, but also for sharing information easily and efficiently. 

2. My Business App

The My Business App template will appeal to small businesses which have a limited technology budget but want to use their website content to create their own app. 

My Business App

The beauty of this template is that it requires no coding knowledge. Using just their website’s URL, in just a few clicks users can convert their website content into an app. The template provides a number of colour themes to match your company’s brand, offers push notifications, and will work equally well on iPhones and iPads.

3. Topics

Topics is a social media app template that helps developers create a forum type app. This is great for businesses because it allows them to create their own space for customers and clients to chat about issues regarding their products or services. 

Topics

Clients can browse topics or search for them, join existing conversations by posting comments, or create a new topic if it doesn’t already exist. The template also provides report features for inappropriate topics, comments, and/or users. This functionality is needed for this type of app in order to pass the submissions review for Apple's App Store.

4. KST Chart

Need to create your own chart on the spot in a meeting? KST Chart app template provides an easy-to-use, highly customisable iOS chart library that business owners will find a handy on-the-go tool.  

KST Chart

The template allows developers to build an app that enables the end user to create a wide variety of charts such as bar, column, and line charts quickly and easily. 

5. TODO App

There is a reason organiser apps are popular in the business category. They help busy people with endless demands on their time organise and prioritise tasks and keep on top of their duties large and small. 

TODO App

For businesses that want to create their own organiser app with features and events relevant to their specific company, there is the TODO App template, which comes with a number of great features like colour themes to match the company’s brand and various viewing options like a Today task page and a Calendar page. In addition, the app is so easy to set up and customise that it doesn't require knowledge of coding to get started. 

6. Secure Notes

The Secure Notes app template allows developers to create a notes app that works with Touch ID and PIN technology to ensure that notes the end user makes on their device are private. 

Secure Notes

This is ideal for business people dealing with sensitive information who may want to make notes on the go but who also want to ensure that what they write stays private. Features include the ability to organise notes by category and to add rich text in the notes. 

7. Eventio

The Eventio app template allows developers to create an event app. End users can create, edit, and delete events and can also create custom categories to organise events. 

Eventio

Events can then be sorted by time or category. The app provides an animated countdown to events which can be customised with a company’s brand. 

8. Video Survey & Review Tool

The Video Survey & Review Tool app template is ideal for businesses that want to create a customer survey app allowing customers to give feedback about a product or service. 

Video Survey  Review Tool

Companies are able to create their survey questions using the app, and their clients then answer the questionnaire through video via the app. The app template is easy to customise, and its features include a detailed analytics report and full integration with a cloud service of your choice. 

9. Multi-Language Translator

Today, many businesses interact with people across the globe, and for those times when you’re confronted with a speaker of a language you aren’t fluent in, a good translator app is a necessity. 

Multi-Language Translator

The Multi-Language Translator app template allows developers to create an app that is capable of translating over 200 languages. Aside from the usual language translator, it allows the end user to translate speech to text and text to speech. This makes conversation between speakers of different languages not only possible but far more fluid than before. 

10. AskIt

Customer service is one of those aspects of business that can definitely make or break a company, and the AskIt app template aims at helping companies make it when it comes to supporting their customers. 

AskIt

The template allows developers to create a specialised question-and-answer messaging app where clients and customers can message their queries and designated employees can message an answer. What’s more, other customers have access to these questions and answers, which helps to reduce duplication and save time. 

Some of the great features available with this app are the ability to search questions using keywords, the ability for users to like questions and answers, and the ability to report abusive contents. 

Conclusion

These 10 best iOS app templates for business are just a small selection of the hundreds of  iOS app templates we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills building iOS apps and templates, then check out some of the ever-so-useful iOS tutorials we have on offer!

2018-06-29T12:22:17.000Z2018-06-29T12:22:17.000ZNona Blackman

Building a Shopping List Application With CloudKit: Sharing Shopping Items

$
0
0

In the previous tutorial of this series, you added the ability to create, update and remove shopping lists from on your iCloud-powered shopping-list app. In the final tutorial of the series, you'll make use of CKShare to share a specific shopping list item with another user. 

In this series, you have worked with private databases, as well as learning about public databases. However, until WWDC 2016, when Apple introduced CKShare, there was no proper way for apps to share data. Private databases are only available to users who are logged in, whereas public databases are designed for public content and allow anyone to view records. When using some of Apple’s very own iCloud apps, however, such as Pages, Keynote or Notes, you may have noticed by selecting the share button, the ability to invite other users to access your data. 

In this post, I'll show you how to share content selectively.

Apples Notes app

In this tutorial, you'll give your app the same ability, so users can collaborate with you on a shared shopping list item. 

Prerequisites

Remember that I will be using Xcode 9 and Swift 3. If you are using an older version of Xcode, then keep in mind that you are using a different version of the Swift programming language.

In this tutorial, we continue where we left off in the third tutorial of this series. You can download or clone the project from GitHub.

About Databases

Apple provides three types of databases: public, private, and shared. A public database is where you make available content that everyone can access, all within the default zone. Users don’t need even to be authenticated with iCloud to view the content, but they can't write changes. 

A private database you should be familiar with already, as the shopping app has been leveraging the private database to store records that the public cannot access. Right now, all of your shopping lists are private lists. 

A shared database is Apple’s shared database window into your private database, which grants users access to read or write via CKShare

It's important to note that the shared database resides on the invited user’s account and is a portal to the owner’s private database, with the CKShare being a particular type of CKRecord that is attached to the CKRecord

The various types of databases

Adding the UICloudSharingController

You will first implement the UICloudSharingController and its associated UICloudSharingControllerDelegate. By far the easiest approach to sharing is to use UICloudSharingController, which takes care of providing and presenting the screens for sharing your record, inviting users, and setting permissions to your record, all with a few lines of code. According to Apple’s SDK, UICloudSharingController effortlessly enables you to:

  • invite people to view or collaborate on a shared record
  • set the access rights determining who can access the shared record (only people invited or anyone with the share link)
  • set general or individual permissions (read-only or read/write)
  • remove access from one or more participants
  • stop participating (if the user is a participant)
  • stop sharing with all participants (if the user is the owner of the shared record)

In your ListViewController.swift file, include the UICloudSharingControllerDelegate delegate:

Next, add the TableView’s didSelectRowAt: method so that when a user selects a cell, it summons the sharing sheet. 

In the method above, you create a CKShare, associating the item CKRecord as the root record. The method then sets the share[CKShareTitleKey] and share[CKShareTypeKey] properties in preparation for displaying the shared record. The method finally calls prepareToShare, passing in the original record as well as the just-created shared record, which you will implement next:

This method creates the UICloudSharingController within a block handler, by first saving the records using the CKModifyRecordsOperation into your private cloud database, before notifying the completion handler. You also set the available permissions of the view controller, before finally presenting it to your user. 

Implementing the UICloudSharingController Delegate Methods

You also need to implement the two mandatory delegate methods, itemTitleForCloudSharingController and failedToSaveShareWithError. There are other optional delegate methods that you may also opt to implement.

The itemTitleForCloudSharingController method matches the CKShareTitleKey property you set earlier, requesting the title to display on the invitation list. failedToSaveShareWithError notifies the delegate to handle failed sharing requests. Go ahead and build and run your app, create a record, and then select an individual record to trigger the sharing sheet. 

Sharing your record

This looks good, but your job is still not complete! You need to handle how the other users can receive and display your shared record.

Receive and Handle CKShare Records

Finally, you need to set up your app to be able to fetch and display shared records. Open your AppDelegate.swift file and add the userDidAcceptCloudKitShareWith delegate method:

UserDidAcceptCloudKitShareWith: notifies the delegate that your app has access to shared information, giving you the opportunity to handle the new content. It notifies you when your app has successfully shared an item, as well as notifying you of issues during the sharing process, through the CKAcceptSharesOperation

In the method, you create a new instance of the AddItemViewController, calling in a new function that you create, fetchShare, along with the metadata of interest. The method finally adds the CKAcceptSharesOperation to your container. To display the record, open the AddItemViewController.swift file, and implement the fetchShare method:

In this final method, you are fetching the shared record and assigning it to your global variable self.item, before finally persisting the operation on your user’s own sharedCloudDatabase database. 

Conclusion

In this tutorial, you learned how easy it is, with just a few lines of code, to add the ability to share a subset of your private records with other users and have them collaborate on that very same data. Through the sheer power and simplicity of CKShare, you can select a shopping list item, invite a user to access your item via the UICloudSharingController sheet, and manage user access and permissions. 

In addition to sharing your records with users, you also learned how to receive and display data within their apps, as well as storing the record in their shared database.

As you can see, CloudKit provides a lot of convenience and robustness, all within Apple’s ecosystem. Authenticating is virtually invisible, without the need for users to log in with an email or password, and synchronizing is real-time. Beyond this series, I encourage you to explore more advanced topics, such as synchronizing CloudKit with Core Data or creating your caching logic to manage offline data marshaling. 

2018-07-10T08:00:00.000Z2018-07-10T08:00:00.000ZDoron Katz

Building a Shopping List Application With CloudKit: Sharing Shopping Items

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31409

In the previous tutorial of this series, you added the ability to create, update and remove shopping lists from on your iCloud-powered shopping-list app. In the final tutorial of the series, you'll make use of CKShare to share a specific shopping list item with another user. 

In this series, you have worked with private databases, as well as learning about public databases. However, until WWDC 2016, when Apple introduced CKShare, there was no proper way for apps to share data. Private databases are only available to users who are logged in, whereas public databases are designed for public content and allow anyone to view records. When using some of Apple’s very own iCloud apps, however, such as Pages, Keynote or Notes, you may have noticed by selecting the share button, the ability to invite other users to access your data. 

In this post, I'll show you how to share content selectively.

Apples Notes app

In this tutorial, you'll give your app the same ability, so users can collaborate with you on a shared shopping list item. 

Prerequisites

Remember that I will be using Xcode 9 and Swift 3. If you are using an older version of Xcode, then keep in mind that you are using a different version of the Swift programming language.

In this tutorial, we continue where we left off in the third tutorial of this series. You can download or clone the project from GitHub.

About Databases

Apple provides three types of databases: public, private, and shared. A public database is where you make available content that everyone can access, all within the default zone. Users don’t need even to be authenticated with iCloud to view the content, but they can't write changes. 

A private database you should be familiar with already, as the shopping app has been leveraging the private database to store records that the public cannot access. Right now, all of your shopping lists are private lists. 

A shared database is Apple’s shared database window into your private database, which grants users access to read or write via CKShare

It's important to note that the shared database resides on the invited user’s account and is a portal to the owner’s private database, with the CKShare being a particular type of CKRecord that is attached to the CKRecord

The various types of databases

Adding the UICloudSharingController

You will first implement the UICloudSharingController and its associated UICloudSharingControllerDelegate. By far the easiest approach to sharing is to use UICloudSharingController, which takes care of providing and presenting the screens for sharing your record, inviting users, and setting permissions to your record, all with a few lines of code. According to Apple’s SDK, UICloudSharingController effortlessly enables you to:

  • invite people to view or collaborate on a shared record
  • set the access rights determining who can access the shared record (only people invited or anyone with the share link)
  • set general or individual permissions (read-only or read/write)
  • remove access from one or more participants
  • stop participating (if the user is a participant)
  • stop sharing with all participants (if the user is the owner of the shared record)

In your ListViewController.swift file, include the UICloudSharingControllerDelegate delegate:

Next, add the TableView’s didSelectRowAt: method so that when a user selects a cell, it summons the sharing sheet. 

In the method above, you create a CKShare, associating the item CKRecord as the root record. The method then sets the share[CKShareTitleKey] and share[CKShareTypeKey] properties in preparation for displaying the shared record. The method finally calls prepareToShare, passing in the original record as well as the just-created shared record, which you will implement next:

This method creates the UICloudSharingController within a block handler, by first saving the records using the CKModifyRecordsOperation into your private cloud database, before notifying the completion handler. You also set the available permissions of the view controller, before finally presenting it to your user. 

Implementing the UICloudSharingController Delegate Methods

You also need to implement the two mandatory delegate methods, itemTitleForCloudSharingController and failedToSaveShareWithError. There are other optional delegate methods that you may also opt to implement.

The itemTitleForCloudSharingController method matches the CKShareTitleKey property you set earlier, requesting the title to display on the invitation list. failedToSaveShareWithError notifies the delegate to handle failed sharing requests. Go ahead and build and run your app, create a record, and then select an individual record to trigger the sharing sheet. 

Sharing your record

This looks good, but your job is still not complete! You need to handle how the other users can receive and display your shared record.

Receive and Handle CKShare Records

Finally, you need to set up your app to be able to fetch and display shared records. Open your AppDelegate.swift file and add the userDidAcceptCloudKitShareWith delegate method:

UserDidAcceptCloudKitShareWith: notifies the delegate that your app has access to shared information, giving you the opportunity to handle the new content. It notifies you when your app has successfully shared an item, as well as notifying you of issues during the sharing process, through the CKAcceptSharesOperation

In the method, you create a new instance of the AddItemViewController, calling in a new function that you create, fetchShare, along with the metadata of interest. The method finally adds the CKAcceptSharesOperation to your container. To display the record, open the AddItemViewController.swift file, and implement the fetchShare method:

In this final method, you are fetching the shared record and assigning it to your global variable self.item, before finally persisting the operation on your user’s own sharedCloudDatabase database. 

Conclusion

In this tutorial, you learned how easy it is, with just a few lines of code, to add the ability to share a subset of your private records with other users and have them collaborate on that very same data. Through the sheer power and simplicity of CKShare, you can select a shopping list item, invite a user to access your item via the UICloudSharingController sheet, and manage user access and permissions. 

In addition to sharing your records with users, you also learned how to receive and display data within their apps, as well as storing the record in their shared database.

As you can see, CloudKit provides a lot of convenience and robustness, all within Apple’s ecosystem. Authenticating is virtually invisible, without the need for users to log in with an email or password, and synchronizing is real-time. Beyond this series, I encourage you to explore more advanced topics, such as synchronizing CloudKit with Core Data or creating your caching logic to manage offline data marshaling. 

2018-07-10T08:00:00.000Z2018-07-10T08:00:00.000ZDoron Katz

Learn About Android Activities in Our New Course

$
0
0

If you want to develop Android apps, you need to understand how to create and use Activities. Our new course, Android Fundamentals: Activities, is the perfect introduction to this essential Android concept.

Android Activity

What You’ll Learn

In this course, Annapurna Agrawal will give you a thorough introduction to Android Activities, with all the basic concepts explained. 

Restoring Android Activity State

You'll learn to navigate between Activities, passing data from one to the other. You will also learn about the Activity lifecycle and how to handle configuration changes in case of screen rotation.

Watch the Introduction

 

Take the Course

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 650,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

2018-07-30T08:23:38.000Z2018-07-30T08:23:38.000ZAndrew Blackman

Learn About Android Activities in Our New Course

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31573

If you want to develop Android apps, you need to understand how to create and use Activities. Our new course, Android Fundamentals: Activities, is the perfect introduction to this essential Android concept.

Android Activity

What You’ll Learn

In this course, Annapurna Agrawal will give you a thorough introduction to Android Activities, with all the basic concepts explained. 

Restoring Android Activity State

You'll learn to navigate between Activities, passing data from one to the other. You will also learn about the Activity lifecycle and how to handle configuration changes in case of screen rotation.

Watch the Introduction

 

Take the Course

You can take our new course straight away with a subscription to Envato Elements. For a single low monthly fee, you get access not only to this course, but also to our growing library of over 1,000 video courses and industry-leading eBooks on Envato Tuts+. 

Plus you now get unlimited downloads from the huge Envato Elements library of 650,000+ creative assets. Create with unique fonts, photos, graphics and templates, and deliver better projects faster.

2018-07-30T08:23:38.000Z2018-07-30T08:23:38.000ZAndrew Blackman

10 Best iOS Map App Templates

$
0
0

Any sort of app that involves getting your users from one place to another needs good map integration. Here are the 10 best iOS app templates with map integration to be found at CodeCanyon

Whether you’re interested in building a store, restaurant or city guide app or creating a booking app, take a look below to see some of the best iOS templates with map integration currently available. 

1. Doctor Finder

The Doctor Finder app template helps developers to create an app that will make it easier for users to find medical service providers like doctors, hospitals and pharmacies in any location. Users can sort doctors by speciality, by name, city, or proximity. They can also check a doctor’s, hospital’s or pharmacy’s profiles and ratings. 

Doctor Finder

Other great features:

  • multilingual support
  • AdMob supported
  • ability to book appointments online
  • add ratings and reviews
  • and more

User nodrena says:

“Awesome customer support!” 

2. Store Finder IOS

The Store Finder IOS app template allows you to create an app to help users find stores near them. The app also lets store owners add their store to the app’s listing. Once users identify the store they want, they can go directly to the store’s details for more information like phone and email address, reviews, and ratings.

Store Finder IOS

Other great features:

  • nearest results by default
  • store image gallery
  • different categories of stores
  • displays available ratings and reviews for stores
  • and more

User hayasuliman says:

“Great team to help you if you have any problem with app.”

3. appyMap

The ideal app for travellers, the appyMap app template helps developers create their own "points of interest" app by entering the name, coordinates and description of the location and selecting an accompanying photo. These points of interest can be grouped by categories, and app owners can lock certain sections of the app and make them available only via in-app purchase. 

appyMap

Other great features: 

  • auto layout
  • AdMob 
  • easy configuration
  • directions and estimated time of arrival at location
  • and more

User esito says:

“I’ve never found such clean and clear code in any other template I’ve bought.”

4. Food Delivery

The Food Delivery app template allows end users to find a restaurant of their choice nearby using the integrated map. They can then check details like whether the restaurant is open or closed and what kind of cuisine is on offer, read the menu and item prices, order a meal, and have it delivered to their door. 

Food Delivery

Other great features:

  • restaurants listed by user rating
  • ability to sort restaurant list by radius or by city
  • create a list of favourite restaurants
  • add reviews of restaurants
  • and more

5. Catch The Monsters

Want to create an app similar to the hit Pokémon app? If so, Catch The Monsters app template may be perfect for you. Users of the app search for the monsters around their area. When they get close enough, they can trace the route to the monsters using the integrated map feature. When they find and catch the monsters, they earn points with the goal of getting onto the top 10 leaderboard. 

Catch The Monsters

Other great features: 

  • AdMob banners
  • push notifications
  • stats and caught monster list
  • and more

User TylerDeviGrey says:

“Great code quality. Easy to edit and customer support is very fast and effective.”

6. AroundMe

AroundMe is a universal app template that allows users to enlist the help of other app users to find popular nearby restaurants, stores, cafes, etc. Users can post recommendations, comment on recommendations, ask questions, and mark suggestions as their favourite. 

AroundMe

Other great features:

  • post questions with image and geolocation attachments
  • push notifications for favourites, comments, and thank yous
  • options to delete and report comments/users
  • PDF user guide included
  • and more

User Agispas says:

“Great support every time.”

7. AdForest

AdForest is a classified ads app template for developers or business owners who want to create an app to manage product listings for an ad posting business. The template includes a multi-currency feature and radius search, and the Google Maps integration allows users to get directions to the seller.

AdForest

Other great features:

  • bad word filter
  • push notifications
  • AdMob integrated
  • Google Analytics
  • and more

User everettbfp says:

“The support, design, everything about this item and the scripts bundle team, are all 5 STAR.”

8. City Directory

Imagine an app that gives users instant access to all the popular spots in a city: cinemas, museums, stores, restaurants, post office, etc. That's exactly what the app you can build with the City Directory template will allow users to do. Not only will users get access to detail about the places on the app like phone number, email, address, website and opening times, but with just a few clicks they will also be able to access user reviews and ratings.

City Directory
  • Other great features:
  • AdMob ads integration 
  • push notification
  • place navigation with Google Maps
  • and more

9. Restaurants Finder

Restaurants Finder app template is one of the highest rated apps in this category on CodeCanyon, and as its name suggests, it enables developers to create a database of restaurants which end users of the app can use to find a restaurant of their choice. The nearest restaurants are displayed by default, and map integration provides directions from the user’s location to the restaurant.

Restaurants Finder

Other great features:

  • map automatically zooms in or out to display all pins
  • restaurant image gallery
  • average rating for each restaurant
  • book a table via mail or SMS
  • and more

10. City App

Our final app template is City App, a native swift iOS application template for developers who want to create a city guide showing interesting places around a city. The main difference between City App and the City Directory featured above is that this template uses augmented reality technology to search a place from the user’s location. The app is also integrated with Firebase so it can work in offline mode.

City App

Other great features: 

  • integrated with Firebase authentication, database, storage, and crash reporting
  • AdMob supported
  • Google Maps integrated
  • and more

User vivo231 says:

“Amazing developer! Clean code! Easy to follow and was super quick to respond on issues.”

Conclusion

These top 10 iOS map app templates are just a small selection of the app templates with map integration that we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills building iOS apps and templates, then check out some of our other posts on iOS app development!

2018-07-30T12:13:48.000Z2018-07-30T12:13:48.000ZNona Blackman

10 Best iOS Map App Templates

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-31559

Any sort of app that involves getting your users from one place to another needs good map integration. Here are the 10 best iOS app templates with map integration to be found at CodeCanyon

Whether you’re interested in building a store, restaurant or city guide app or creating a booking app, take a look below to see some of the best iOS templates with map integration currently available. 

1. Doctor Finder

The Doctor Finder app template helps developers to create an app that will make it easier for users to find medical service providers like doctors, hospitals and pharmacies in any location. Users can sort doctors by speciality, by name, city, or proximity. They can also check a doctor’s, hospital’s or pharmacy’s profiles and ratings. 

Doctor Finder

Other great features:

  • multilingual support
  • AdMob supported
  • ability to book appointments online
  • add ratings and reviews
  • and more

User nodrena says:

“Awesome customer support!” 

2. Store Finder IOS

The Store Finder IOS app template allows you to create an app to help users find stores near them. The app also lets store owners add their store to the app’s listing. Once users identify the store they want, they can go directly to the store’s details for more information like phone and email address, reviews, and ratings.

Store Finder IOS

Other great features:

  • nearest results by default
  • store image gallery
  • different categories of stores
  • displays available ratings and reviews for stores
  • and more

User hayasuliman says:

“Great team to help you if you have any problem with app.”

3. appyMap

The ideal app for travellers, the appyMap app template helps developers create their own "points of interest" app by entering the name, coordinates and description of the location and selecting an accompanying photo. These points of interest can be grouped by categories, and app owners can lock certain sections of the app and make them available only via in-app purchase. 

appyMap

Other great features: 

  • auto layout
  • AdMob 
  • easy configuration
  • directions and estimated time of arrival at location
  • and more

User esito says:

“I’ve never found such clean and clear code in any other template I’ve bought.”

4. Food Delivery

The Food Delivery app template allows end users to find a restaurant of their choice nearby using the integrated map. They can then check details like whether the restaurant is open or closed and what kind of cuisine is on offer, read the menu and item prices, order a meal, and have it delivered to their door. 

Food Delivery

Other great features:

  • restaurants listed by user rating
  • ability to sort restaurant list by radius or by city
  • create a list of favourite restaurants
  • add reviews of restaurants
  • and more

5. Catch The Monsters

Want to create an app similar to the hit Pokémon app? If so, Catch The Monsters app template may be perfect for you. Users of the app search for the monsters around their area. When they get close enough, they can trace the route to the monsters using the integrated map feature. When they find and catch the monsters, they earn points with the goal of getting onto the top 10 leaderboard. 

Catch The Monsters

Other great features: 

  • AdMob banners
  • push notifications
  • stats and caught monster list
  • and more

User TylerDeviGrey says:

“Great code quality. Easy to edit and customer support is very fast and effective.”

6. AroundMe

AroundMe is a universal app template that allows users to enlist the help of other app users to find popular nearby restaurants, stores, cafes, etc. Users can post recommendations, comment on recommendations, ask questions, and mark suggestions as their favourite. 

AroundMe

Other great features:

  • post questions with image and geolocation attachments
  • push notifications for favourites, comments, and thank yous
  • options to delete and report comments/users
  • PDF user guide included
  • and more

User Agispas says:

“Great support every time.”

7. AdForest

AdForest is a classified ads app template for developers or business owners who want to create an app to manage product listings for an ad posting business. The template includes a multi-currency feature and radius search, and the Google Maps integration allows users to get directions to the seller.

AdForest

Other great features:

  • bad word filter
  • push notifications
  • AdMob integrated
  • Google Analytics
  • and more

User everettbfp says:

“The support, design, everything about this item and the scripts bundle team, are all 5 STAR.”

8. City Directory

Imagine an app that gives users instant access to all the popular spots in a city: cinemas, museums, stores, restaurants, post office, etc. That's exactly what the app you can build with the City Directory template will allow users to do. Not only will users get access to detail about the places on the app like phone number, email, address, website and opening times, but with just a few clicks they will also be able to access user reviews and ratings.

City Directory
  • Other great features:
  • AdMob ads integration 
  • push notification
  • place navigation with Google Maps
  • and more

9. Restaurants Finder

Restaurants Finder app template is one of the highest rated apps in this category on CodeCanyon, and as its name suggests, it enables developers to create a database of restaurants which end users of the app can use to find a restaurant of their choice. The nearest restaurants are displayed by default, and map integration provides directions from the user’s location to the restaurant.

Restaurants Finder

Other great features:

  • map automatically zooms in or out to display all pins
  • restaurant image gallery
  • average rating for each restaurant
  • book a table via mail or SMS
  • and more

10. City App

Our final app template is City App, a native swift iOS application template for developers who want to create a city guide showing interesting places around a city. The main difference between City App and the City Directory featured above is that this template uses augmented reality technology to search a place from the user’s location. The app is also integrated with Firebase so it can work in offline mode.

City App

Other great features: 

  • integrated with Firebase authentication, database, storage, and crash reporting
  • AdMob supported
  • Google Maps integrated
  • and more

User vivo231 says:

“Amazing developer! Clean code! Easy to follow and was super quick to respond on issues.”

Conclusion

These top 10 iOS map app templates are just a small selection of the app templates with map integration that we have available at CodeCanyon, so if none of them quite fits your needs, there are plenty of other great options to choose from.

And if you want to improve your skills building iOS apps and templates, then check out some of our other posts on iOS app development!

2018-07-30T12:13:48.000Z2018-07-30T12:13:48.000ZNona Blackman

20 Best HTML5 Game Templates of 2018 With Source Code

$
0
0

Over the past several years, we have seen HTML5 used to create many great online solutions. We have also seen it used to create some great fun! With the vanishing of Flash, HTML5 quickly became the universal platform to create browser-based games for both desktop and mobile devices.

Here are the 20 best HTML5 game templates and engines of 2018. Whether you already have a game concept to build or would like a fun way to learn more about making mobile games, download the source code today and get started making something awesome.

1. Banana Jump

If you want to play a game with infinite jumping, give Banana Jump a try. The same can be said if that's what you would like to code!

Banana Jump Capx

Features include:

  • touch and mouse support
  • includes a Construct2 file
  • supports Android and iOS
  • and more

Begin playing, editing, and jumping with Banana Jump.

2. Indiara and the Skull Gold

Indiara and the Skull Gold is a mobile platformer with an Indiana Jones feel to it.

Collect the eight gold skulls, but be on the lookout—the caves are full of traps!

Indiara and the Skull Gold
“Meet and play with Indiara, a girl who loves to collect ancient artifacts.”

Features included:

  • supports both desktop and mobile
  • includes layered PSD and AI files
  • 860x480 graphics
  • and more

Easily reskin this HTML5 game template by editing and replacing the images.

Indiara and the Skull Gold includes eight complete levels and can be completely customized by using Construct 2.

3. Don't Crash

Don't crash while you play Don't Crash!

As two cars race around the track, tap the screen to change lanes and avoid a crash.

Dont Crash
“Don’t crash—this is the only rule of the game.”

Features include:

  • supports both mobile and desktop
  • easy, one-touch control
  • 1280x720 graphics
  • and more

Reskin this HTML5 game using the included AI files or completely change the game elements using Construct 2.

Dont Crash is simple, fast, and addictive.

4. Game FlapCat Steampunk

Game FlapCat Steampunk is a cute and simple HTML5 game that's perfectly made for mobile.

How high can you score?

Game FlapCat Steampunk
“Help the cat FlapCat to go through challenges that are super difficult.”

Features include:

  • includes PSD and AI files
  • 1280x720 graphics
  • infinite level
  • and more

Whether you're playing in your web browser or mobile phone, all you need is a single touch or mouse click to play. Easy to play, hard to master.

Game FlapCat Steampunk can easily be re-skinned by replacing the images or fully customized with Construct 2.

5. Smiley Ball

Smiley Ball will put a smile on your face.

Actually, 1 of 5 different smilies.

Smiley Ball

Built with Construct 2, it supports both desktop and mobile devices, and it is easy to change out the elements and edit the source code to make your own game.

With five different smilies to choose from, the Smiley Ball adventure will take you through 20 levels full of spikes and obstacles to avoid before reaching your goal.

6. Jumper Frog

Frogger is a classic arcade game that makes a great adaptation to mobile.

Take a leap and jump on Jumper Frog for some fun.

Jumper Frog - HTML5 Game

“Enjoy this colorful version of the classic game Frogger.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • fully customizable
  • and more

This is also compatible with CTL Arcade.

Jumper Frog brings this arcade classic to any screen.

7. Bubble Shooter

Launch the colorful bubble into place, and when you get three or more in a row, they disappear. Clear all the bubbles to win!

Bubble Shooter is a classic puzzler that's easy to learn, but hard to master.

Bubble Shooter - HTML5 Games
“The goal of the game is to clear all the bubbles from the level avoiding any bubble crossing the bottom line.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • fully customizable
  • and more

If you think this HTML5 game is fun, be sure to also consider the 50 Levels Pack.

Bubble Shooter is also compatible with CTL Arcade.

8. Diamond Hunter

Diamond Hunter is a fast-paced avoidance game: avoid rocks and bombs, while you collect diamonds.

Diamond Hunter - HTML5 Avoidance Game

Features include:

  • HTML5 mobile optimized
  • Android, iOS, multi-platform
  • uses Construct 2 and 3 native plugins
  • and more

Diamond Hunter provides a retro feel and includes all game assets.

9. Katana Fruits

If you're familiar with Fruit Ninja, you'll be familiar with Katana Fruits.

Katana Fruits - HTML5 Game
“The goal is to cut all the fruits that appear on the screen without dropping them and avoid the bombs.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • promote with social share buttons
  • fully customizable
  • and more

This HTML5 game is compatible with CTL Arcade for WordPress and can be easily customized.

Sharpen your Katana, it's time to slash some fruit with the Katana Fruits.

10. The Sorcerer

The moment the screen loads, you'll know what to do. Inspired by Zuma, The Sorcerer is an instant puzzle game hit.

The Sorcerer - HTML5 Puzzle Game
“The Sorcerer was awarded as the best puzzle game in HTML5 Most Wanted contest”

Features include:

  • fully developed in HTML5 and CreateJS
  • source code included
  • fully customizable
  • and more

Mobile or desktop, the 960x540 resolution is fully optimized.

The Sorcerer is hard to put down, so you may want to consider acquiring extra levels, too.

11. Rearrange Letters

You're given a clue and a jumbled mess of letters. With the clue in mind, rearrange the letters until you've got the word right as the timer counts down.

That's how the Rearrange Letters HTML 5 game works.

Rearrange Letters - HTML5 Game
“Rearrange Letters is an HTML5 game where you can arrange the letters and make the right word with the given description as a clue.”

Features include:

  • customize the text, game mode, and timer
  • social media high score sharer
  • mouse and touch control
  • 1024x768 resolution
  • and more

With plenty of customizations and built using CreateJS, you can reimagine Rearrange Letters any way you like.

12. Rolling Cheese

The Rolling Cheese physics game has a tiny hero: help this little hungry mouse get the cheese by rolling it through obstacle courses to reach the mouse.

Rolling Cheese - HTML5 Physics Game

Features include:

  • fully customizable with included source code
  • optimized for both mobile and desktop
  • developed in HTML5, JavaScript, and CreateJS
  • and more

Rolling Cheese is one of the few games in this list not designed using Construct or a similar framework.

13. Smath Pong

Smath Pong is a casual game where the objective is to keep hitting the ball for as long as possible—but the ball moves faster and faster with time.

Smath Pong C2  C3  HTML Game

Features include:

  • easy to edit
  • uses Construct2 and Construct3
  • infinite levels
  • includes files (.capx, c3p, .html, .png, .m4a, .ogg)
  • and more

Smath Pong includes documentation and needs no programming knowledge to edit.

14. Zombie Defense

A zombie defense HTML5 game? Yes, please.

Your objective is to shoot the zombies as they walk towards you, lowering their health meter with every shot.

Features include:

  • mobile and desktop optimized
  • supports mouse/keyboard
  • HTML5 files and documentation
  • and more

The Zombie Defense is ready to edit—or play.

15. Quiz Game

Build your own custom mobile quiz game using Quiz Game.

Quiz Game - HTML5 Game
"Quiz Game is a HTML5 game with free general knowledge quiz questions and multiple choice answers."

Features include:

  • built-in editor tool
  • 17 different answer layouts
  • optional audio for questions and answers
  • optional right and wrong answer animations
  • option to display the correct answer
  • fully responsive
  • built with CreateJS
  • and more

With the questions, answers, and category loaded from an XML file, you'll be able to spin up many different types of quizzes using Quiz Game.

16. Sweety Memory

Do you remember Memory? Sweety Memory is an HTML 5 game that works the same way. Flip the cards, make the matches, and win!

Sweety Memory - HTML5 Game
“Match all the identical cards before time runs out!”

Features include:

  • fully customizable with included PSD and AI files
  • fully developed in HTML5 and CreateJS
  • source code included
  • and more

Mobile or desktop, the 960x1200 resolution scales to fit the whole screen of almost any device.

Sweety Memory is also compatible with CTL Arcade.

17. 3D BlackJack

3D BlackJack is an HTML5 casino game that isn't designed to be used with real money—it is simply a fun game to play.

HTML5 3D BlackJack - HTML5 Casino Game
“Enjoy this blackjack game with hi-res 3D graphics!”

Features include:

  • fully customizable HTML5 and CreateJS files
  • insurance feature, double bet, and split hand
  • PSD and AI files for easy customization
  • and more

This HTML5 game is also compatible with CTL Arcade for WordPress.

You can easily monetize your app with banner ads and promote it with the social share buttons included with 3D BlackJack.

18. 3D Roulette

This is another high-quality casino game built for fun. The 3D Roulette game includes many great features and is designed really well.

3D Roulette - HTML5 Casino Game
“The game contains all the main roulette game features like Voisins zero, tier, orphelins, neighbor, final bets.”

Features include:

  • fully customizable HTML5 and CreateJS files
  • PSD and AI files for easy customization
  • fully responsive 750x600 resolution
  • and more

This HTML5 game is also compatible with CTL Arcade for WordPress, but if you're looking for a mobile-centric version, I recommend Roulette Royale.

3D Roulette is the perfect desktop, in-browser roulette HTML5 game.

19. Missiles Again

Missiles Again is a fun time-killer that works on almost every possible platform.

Missiles Again - HTML5 game Construct 2 Capx  Admobvvvvvvvvvvvvvvvvvvvvvvvv
“Control the plane to collect all stars and avoid all missiles!”

Features include:

  • easy code that can be customized with Construct 2
  • PNG and PSD files for easy reskin
  • supports AdMob Ads
  • and more

A fun, well-designed HTML5 game, Missiles Again is one you don't want to miss.

20. HTML5 Game Bundles

Sometimes it's better to buy in bulk.

If you are considering multiple HTML5 games, you may want to look through these HTML5 Game Bundles to see if you can pay less and receive more.

HTML5 Game Bundles

A few titles from various bundles include:

  • Fruit Slasher
  • Brick Out
  • Ninja Run
  • Tank Defender
  • Billiards
  • Cars
  • Monster Match-3
  • Bubble Shooter
  • Space Purge
  • Duck Shooter
  • Girl Dress Up
  • and more!

Some of the best HTML5 Game Bundles to consider include Super Bundle No 1 (50 games), 24-Games in 1 Bundle, and HTML5 Games Bundle No. 2 (9 games).

Conclusion

Going through this list may inspire you to reskin, tweak, or build something completely new—using one of these HTML5 games as a template towards success. Whether you publish a game arcade on your website, earn revenue with advertising, or would like to dig deeper in HTML5 using game templates, you're sure to find something you're looking for from the Envato Market.

You can also find useful Envato Tuts+ code tutorials on game design or game mechanics, as well as HTML5 tutorials to get you started.

Gaming and coding. Two things that are incredibly fun to do, and even better together!

2018-08-09T02:54:18.685Z2018-08-09T02:54:18.685ZEric Dye

20 Best HTML5 Game Templates of 2018 With Source Code

$
0
0
tag:code.tutsplus.com,2005:PostPresenter/cms-28892

Over the past several years, we have seen HTML5 used to create many great online solutions. We have also seen it used to create some great fun! With the vanishing of Flash, HTML5 quickly became the universal platform to create browser-based games for both desktop and mobile devices.

Here are the 20 best HTML5 game templates and engines of 2018. Whether you already have a game concept to build or would like a fun way to learn more about making mobile games, download the source code today and get started making something awesome.

1. Banana Jump

If you want to play a game with infinite jumping, give Banana Jump a try. The same can be said if that's what you would like to code!

Banana Jump Capx

Features include:

  • touch and mouse support
  • includes a Construct2 file
  • supports Android and iOS
  • and more

Begin playing, editing, and jumping with Banana Jump.

2. Indiara and the Skull Gold

Indiara and the Skull Gold is a mobile platformer with an Indiana Jones feel to it.

Collect the eight gold skulls, but be on the lookout—the caves are full of traps!

Indiara and the Skull Gold
“Meet and play with Indiara, a girl who loves to collect ancient artifacts.”

Features included:

  • supports both desktop and mobile
  • includes layered PSD and AI files
  • 860x480 graphics
  • and more

Easily reskin this HTML5 game template by editing and replacing the images.

Indiara and the Skull Gold includes eight complete levels and can be completely customized by using Construct 2.

3. Don't Crash

Don't crash while you play Don't Crash!

As two cars race around the track, tap the screen to change lanes and avoid a crash.

Dont Crash
“Don’t crash—this is the only rule of the game.”

Features include:

  • supports both mobile and desktop
  • easy, one-touch control
  • 1280x720 graphics
  • and more

Reskin this HTML5 game using the included AI files or completely change the game elements using Construct 2.

Dont Crash is simple, fast, and addictive.

4. Game FlapCat Steampunk

Game FlapCat Steampunk is a cute and simple HTML5 game that's perfectly made for mobile.

How high can you score?

Game FlapCat Steampunk
“Help the cat FlapCat to go through challenges that are super difficult.”

Features include:

  • includes PSD and AI files
  • 1280x720 graphics
  • infinite level
  • and more

Whether you're playing in your web browser or mobile phone, all you need is a single touch or mouse click to play. Easy to play, hard to master.

Game FlapCat Steampunk can easily be re-skinned by replacing the images or fully customized with Construct 2.

5. Smiley Ball

Smiley Ball will put a smile on your face.

Actually, 1 of 5 different smilies.

Smiley Ball

Built with Construct 2, it supports both desktop and mobile devices, and it is easy to change out the elements and edit the source code to make your own game.

With five different smilies to choose from, the Smiley Ball adventure will take you through 20 levels full of spikes and obstacles to avoid before reaching your goal.

6. Jumper Frog

Frogger is a classic arcade game that makes a great adaptation to mobile.

Take a leap and jump on Jumper Frog for some fun.

Jumper Frog - HTML5 Game

“Enjoy this colorful version of the classic game Frogger.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • fully customizable
  • and more

This is also compatible with CTL Arcade.

Jumper Frog brings this arcade classic to any screen.

7. Bubble Shooter

Launch the colorful bubble into place, and when you get three or more in a row, they disappear. Clear all the bubbles to win!

Bubble Shooter is a classic puzzler that's easy to learn, but hard to master.

Bubble Shooter - HTML5 Games
“The goal of the game is to clear all the bubbles from the level avoiding any bubble crossing the bottom line.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • fully customizable
  • and more

If you think this HTML5 game is fun, be sure to also consider the 50 Levels Pack.

Bubble Shooter is also compatible with CTL Arcade.

8. Diamond Hunter

Diamond Hunter is a fast-paced avoidance game: avoid rocks and bombs, while you collect diamonds.

Diamond Hunter - HTML5 Avoidance Game

Features include:

  • HTML5 mobile optimized
  • Android, iOS, multi-platform
  • uses Construct 2 and 3 native plugins
  • and more

Diamond Hunter provides a retro feel and includes all game assets.

9. Katana Fruits

If you're familiar with Fruit Ninja, you'll be familiar with Katana Fruits.

Katana Fruits - HTML5 Game
“The goal is to cut all the fruits that appear on the screen without dropping them and avoid the bombs.”

Features include:

  • includes PSD and AI files for customization
  • fully developed in HTML5 and CreateJS
  • promote with social share buttons
  • fully customizable
  • and more

This HTML5 game is compatible with CTL Arcade for WordPress and can be easily customized.

Sharpen your Katana, it's time to slash some fruit with the Katana Fruits.

10. The Sorcerer

The moment the screen loads, you'll know what to do. Inspired by Zuma, The Sorcerer is an instant puzzle game hit.

The Sorcerer - HTML5 Puzzle Game
“The Sorcerer was awarded as the best puzzle game in HTML5 Most Wanted contest”

Features include:

  • fully developed in HTML5 and CreateJS
  • source code included
  • fully customizable
  • and more

Mobile or desktop, the 960x540 resolution is fully optimized.

The Sorcerer is hard to put down, so you may want to consider acquiring extra levels, too.

11. Rearrange Letters

You're given a clue and a jumbled mess of letters. With the clue in mind, rearrange the letters until you've got the word right as the timer counts down.

That's how the Rearrange Letters HTML 5 game works.

Rearrange Letters - HTML5 Game
“Rearrange Letters is an HTML5 game where you can arrange the letters and make the right word with the given description as a clue.”

Features include:

  • customize the text, game mode, and timer
  • social media high score sharer
  • mouse and touch control
  • 1024x768 resolution
  • and more

With plenty of customizations and built using CreateJS, you can reimagine Rearrange Letters any way you like.

12. Rolling Cheese

The Rolling Cheese physics game has a tiny hero: help this little hungry mouse get the cheese by rolling it through obstacle courses to reach the mouse.

Rolling Cheese - HTML5 Physics Game

Features include:

  • fully customizable with included source code
  • optimized for both mobile and desktop
  • developed in HTML5, JavaScript, and CreateJS
  • and more

Rolling Cheese is one of the few games in this list not designed using Construct or a similar framework.

13. Smath Pong

Smath Pong is a casual game where the objective is to keep hitting the ball for as long as possible—but the ball moves faster and faster with time.

Smath Pong C2  C3  HTML Game

Features include:

  • easy to edit
  • uses Construct2 and Construct3
  • infinite levels
  • includes files (.capx, c3p, .html, .png, .m4a, .ogg)
  • and more

Smath Pong includes documentation and needs no programming knowledge to edit.

14. Zombie Defense

A zombie defense HTML5 game? Yes, please.

Your objective is to shoot the zombies as they walk towards you, lowering their health meter with every shot.

Features include:

  • mobile and desktop optimized
  • supports mouse/keyboard
  • HTML5 files and documentation
  • and more

The Zombie Defense is ready to edit—or play.

15. Quiz Game

Build your own custom mobile quiz game using Quiz Game.

Quiz Game - HTML5 Game
"Quiz Game is a HTML5 game with free general knowledge quiz questions and multiple choice answers."

Features include:

  • built-in editor tool
  • 17 different answer layouts
  • optional audio for questions and answers
  • optional right and wrong answer animations
  • option to display the correct answer
  • fully responsive
  • built with CreateJS
  • and more

With the questions, answers, and category loaded from an XML file, you'll be able to spin up many different types of quizzes using Quiz Game.

16. Sweety Memory

Do you remember Memory? Sweety Memory is an HTML 5 game that works the same way. Flip the cards, make the matches, and win!

Sweety Memory - HTML5 Game
“Match all the identical cards before time runs out!”

Features include:

  • fully customizable with included PSD and AI files
  • fully developed in HTML5 and CreateJS
  • source code included
  • and more

Mobile or desktop, the 960x1200 resolution scales to fit the whole screen of almost any device.

Sweety Memory is also compatible with CTL Arcade.

17. 3D BlackJack

3D BlackJack is an HTML5 casino game that isn't designed to be used with real money—it is simply a fun game to play.

HTML5 3D BlackJack - HTML5 Casino Game
“Enjoy this blackjack game with hi-res 3D graphics!”

Features include:

  • fully customizable HTML5 and CreateJS files
  • insurance feature, double bet, and split hand
  • PSD and AI files for easy customization
  • and more

This HTML5 game is also compatible with CTL Arcade for WordPress.

You can easily monetize your app with banner ads and promote it with the social share buttons included with 3D BlackJack.

18. 3D Roulette

This is another high-quality casino game built for fun. The 3D Roulette game includes many great features and is designed really well.

3D Roulette - HTML5 Casino Game
“The game contains all the main roulette game features like Voisins zero, tier, orphelins, neighbor, final bets.”

Features include:

  • fully customizable HTML5 and CreateJS files
  • PSD and AI files for easy customization
  • fully responsive 750x600 resolution
  • and more

This HTML5 game is also compatible with CTL Arcade for WordPress, but if you're looking for a mobile-centric version, I recommend Roulette Royale.

3D Roulette is the perfect desktop, in-browser roulette HTML5 game.

19. Missiles Again

Missiles Again is a fun time-killer that works on almost every possible platform.

Missiles Again - HTML5 game Construct 2 Capx  Admobvvvvvvvvvvvvvvvvvvvvvvvv
“Control the plane to collect all stars and avoid all missiles!”

Features include:

  • easy code that can be customized with Construct 2
  • PNG and PSD files for easy reskin
  • supports AdMob Ads
  • and more

A fun, well-designed HTML5 game, Missiles Again is one you don't want to miss.

20. HTML5 Game Bundles

Sometimes it's better to buy in bulk.

If you are considering multiple HTML5 games, you may want to look through these HTML5 Game Bundles to see if you can pay less and receive more.

HTML5 Game Bundles

A few titles from various bundles include:

  • Fruit Slasher
  • Brick Out
  • Ninja Run
  • Tank Defender
  • Billiards
  • Cars
  • Monster Match-3
  • Bubble Shooter
  • Space Purge
  • Duck Shooter
  • Girl Dress Up
  • and more!

Some of the best HTML5 Game Bundles to consider include Super Bundle No 1 (50 games), 24-Games in 1 Bundle, and HTML5 Games Bundle No. 2 (9 games).

Conclusion

Going through this list may inspire you to reskin, tweak, or build something completely new—using one of these HTML5 games as a template towards success. Whether you publish a game arcade on your website, earn revenue with advertising, or would like to dig deeper in HTML5 using game templates, you're sure to find something you're looking for from the Envato Market.

You can also find useful Envato Tuts+ code tutorials on game design or game mechanics, as well as HTML5 tutorials to get you started.

Gaming and coding. Two things that are incredibly fun to do, and even better together!

2018-08-09T02:54:18.685Z2018-08-09T02:54:18.685ZEric Dye
Viewing all 1836 articles
Browse latest View live